HTML inside of JLabels

I have been working around using java formatting for some time now by using HTML inside of my Swing objects. I had a couple of questions about this practice.
Is it worth it? and if not, what should I do instead.
Why dont link statements work inside of the text. <a href.....
Is there a good resource for java formatting?
I could easily start learning XML, would this be any better?
Thanks for the advice.
Leon

Though the HTML form and the swing page appear similar their functions are rather different. The business of the HTML page is just to display information, and maybe send a few selected fields back. More often just to switch to another page when it's been read.
The GUI window is much more interactive, with every element potentially communicating with the program on an individual basis.
So the tools are bound to be different. If you want to write pages that can be displayed either way and hide the differences as much as possible you should look at Java Faces.
Links can't work the same way because the meaning of a link on a browser is tied up in what the browser does. The GUI application isn't in the business of displaying another HTML page based on a URL (if it was, it would be a browser).

Similar Messages

  • Problem with HTML in a JLabel

    Is it possible to use styles when using HTML in a JLabel?
    Example:
    <html><hr style="height: 1px; color: black;"></html>Doesn't work correctly as this should give a solid 1px high hr, but doesn't. Instead it gives a black hr with a white shade...
    The JLabel it is used in is not customized in any way.

    I too am interested in getting color on an HR to work. Can you summarize what you have done to date? Sample code?
    Note: An easy way to correct it in a Nonframe instance of html is to subclass HTMLEditor to implement your own ViewFactory and own HRuleView which checks the attribute tag color for the color. I've got this to work, but frames don't work since you can call FrameView (not public) and thus have to use the super class - which then by-passes the ViewFactory from then on.
    So a NON-FRAME Solution to give HR color is... Anybody have a better global solution?
    Here is the one line fix to HRuleView .setProperties. So if you subclass HRuleView specifically to do
    public class MyHTMLEditorKit extends HTMLEditorKit { // StyledEditorKit
        private static final ViewFactory defaultFactory = new MyHTMLFactory();
        public static class MyHTMLFactory extends HTMLFactory {//implements ViewFactory {
             public View create(Element elem) {
             Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute);
             if (o instanceof HTML.Tag) {
              HTML.Tag kind = (HTML.Tag) o;
              if (kind == HTML.Tag.HR) {
                  return new MyHRuleView(elem);
           return super.create(elem);
    class MyHRuleView extends View  {
         private Color color = null;
         public void setPropertiesFromAttributes() {
              super.setPropertiesFromAttributes();
              try {color = new Color(Integer.decode((String)attr.getAttribute("color")).intValue());} catch (Exception e) {}
         public void paint(Graphics g, Shape a) {
              if (color != null) g.setColor(color);
              super.paint(g, a);
    }

  • Open html inside flash it´s posible?

    open html inside flash it´s posible?

    I've been trying to create a link in flash8, to link to an
    html page the whole week, no success at all. I dont think anyone in
    this
    forum's got any answer to that. When I run the swf file alone
    it works but as soon as I import it into Dreamweaver, all links to
    an html file created in flash fails.But if by any chance you get
    the answer please would u send it to this emall address:
    [email protected]

  • HTML on A JLabel ARRRGGGGHHHH!!!!

    Okay - I've used the functionality of putting html in a JLabel before fine, I think it's pretty useful.
    Unfortunately I've just written a modal dialog inner class where it just won't wrap at the edge of the screen, someone please tell me why...!
    Here's the code
    * Modal config dialog box.
    private class RefreshDialog extends JDialog
    private JButton _okayButton = new JButton("OK");
    private JButton _cancelButton = new JButton("Cancel");
    private String _sCurrentText;
    private JTextField _periodField;
    private JLabel _topText = new JLabel("<html><p>Changing the refresh rate will change the " +
    "frequency of chart updates. Please select from the below.</html>");
    private int _nMultiplicationFactor = 1;
    private String _sSeconds = "Seconds";
    private String _sMinutes = "Minutes";
    private String _sHours = "Hours";
    private JComboBox _unitCombo = new JComboBox(new Object []{_sSeconds, _sMinutes, _sHours});
    * Create an Update Dialog with the delay set to the specified number of seconds
    * @param parent Parent container.
    * @param nDelay the refresh rate in seconds
    public RefreshDialog(JFrame parent)
    super(parent, "Change refresh rate", true);
    this.setLocation(parent.getLocation());
    Container contentPane = this.getContentPane();
    JPanel northPanel = new JPanel();
    JPanel ratePanel = new JPanel();
    BoxLayout rateEntryLayout = new BoxLayout(ratePanel, BoxLayout.X_AXIS);
    JPanel okayCancelPanel = new JPanel();
    BoxLayout okayCancelLayout = new BoxLayout(okayCancelPanel, BoxLayout.X_AXIS);
    //calculate the default setting for delay passed in
    if ( m_nChartRefreshDelay < 60 )
    sCurrentText = String.valueOf(mnChartRefreshDelay);
    unitCombo.setSelectedItem(sSeconds);
    else if (m_nChartRefreshDelay < 3600)
    sCurrentText = String.valueOf(mnChartRefreshDelay/60.00);
    unitCombo.setSelectedItem(sMinutes);
    else
    sCurrentText = String.valueOf(mnChartRefreshDelay/3600.00);
    unitCombo.setSelectedItem(sHours);
    periodField = new JTextField(sCurrentText, 4);
    JLabel label = new JLabel("Update every ");
    _topText.setBorder(BorderFactory.createEmptyBorder(4, 3, 5, 3));
    northPanel.add(_topText);
    contentPane.add(northPanel, BorderLayout.NORTH);
    ratePanel.add(label);
    ratePanel.add(_periodField);
    ratePanel.add(_unitCombo);
    contentPane.add(ratePanel, BorderLayout.CENTER);
    okayCancelPanel.add(_okayButton);
    okayCancelPanel.add(_cancelButton);
    contentPane.add(okayCancelPanel, BorderLayout.SOUTH);
    _cancelButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae){
    RefreshDialog.this.dispose();
    _okayButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae){
    //do some action
    setResizable(true);
    this.setSize(400, 200);
    }

    Okay - I've worked it out - doesn't work in BorderLayout for some reason. Put it in a Box Layout and everything is fine......
    ..don't ask me why???

  • HtML inside JSP Tag

    How much HTML can be inside a JSP Tag? I created a tag which set few variables. Now on the JSP page, if the variable A is not null, then only display value and show a link next to it.
    So is it OK, if I take the link html (href code) and concatenate with the vale of A
    Thanks in advance

    <ed:TableIterator resultId="calist">
      <tr class="altrow">
        <td class="center" style="vertical-align:top;">
          <input type="checkbox" onchange="ca.value='1';" class="cb" name="cadel" value="<ed:getColumn column="idx"/>"/>
          <input type="hidden" name="cadate" value="<ed:getColumn column="date"/>"/>
        </td>
        <td style="vertical-align:top;">
          <input type="text" onchange="ca.value='1';" class="text" name="caoms" value="<ed:getColumn column="title"/>"/>
        </td>
        <td>
          <textarea class="text" onchange="ca.value='1';" name="camemo" cols="40" rows="4"><ed:getColumn column="memo"/></textarea>
        </td>
      </tr>
    </ed:TableIterator>Loads :)
    This is a small sample, building the rows of a table with 3 columns (a checkbox, an inputfield and a textarea) for each row.
    I've built larger structures where I nest the same tags to create select controls in each row.
    I wouldn't actually create HTML inside the java class for the tag, as that violates the separation of code and presentation (that's not to say I haven't done it, but I've learned better since <GRIN> and now try to avoid it where possible and minimise it where not).

  • Embedding HTML inside Flash File

    HI.
    I would like to inquire on how to embed a HTML file insides a
    Flash File.
    This is the scenario, I have several HTML files, e.g. a.html,
    b.html, c.html.
    Where there would be a links inside that flash file, to open
    a.html, b.html, and c.html (not a new browser).
    How can I do this? Guides / Tutorials would help.
    I am a bit a newbie in the world of Flash. Thank you in
    advance.
    /928 :)

    mauve928,
    > I would like to inquire on how to embed a HTML file
    insides
    > a Flash File.
    Dynamic text fields do support some HTML formatting, but
    it's important
    to understand that at this time, the supported tags comprise
    only a very
    small subset of the full HTML specification. (Search the Help
    panel for
    "supported HTML tags," and you'll see which ones they are.)
    As such, Flash
    Player simply doesn't load HTML files.
    What Flash Player does load is XML, so if your documents are
    formatted
    as XHTML (that is, technically XML), you'll have the
    beginnings of something
    you can use. Flash won't necessarily be able to display
    elements it doesn't
    understand (e.g. tables), but because the document is XML,
    you'll be able to
    parse those tags and extract information from them, using
    what Flash *is*
    capable of displaying.
    I wrote a series at Community MX not long ago that makes
    some
    exploration into what you're after.
    http://www.communitymx.com/abstract.cfm?cid=02395
    The first article (of three) is free, and you sign up for a
    non-obligatory free trial to read the rest.
    David Stiller
    Co-author, Foundation Flash CS3 for Designers
    http://tinyurl.com/2k29mj
    "Luck is the residue of good design."

  • Application starts IE and needs to access html inside Jar

    Hi everyone,
    I have a Swing application which i have deployed as an executable Jar file. One of the options i give the users within this application is the ability to view a html file in their default browser. However the html file is packaged within the jar and i cannot get Internet Explorer to target the html file when it exists inside the jar.
    I fire up IE using the following command :
    Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler <path to html file>" ).
    The above command works no problem if my html file exists on my hard drive so for example the following works no problem:
    Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler C:\test\help.html" )
    I have tried the following command by getting the URL for the html file using :
    URL theURL = myClass.class.getClassLoader().getSystemResource( "help.html" );
    I then get a path to the file:
    File aFile = new File( theURL.getFile() );
    String htmlFile = aFile.getAbsolutePath();
    and execute the command
    Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler" + " " + htmlFile )
    However this was not successfull either.Can anyone tell me how i might get internet explorer to display a html file which is packaged within a jar.
    Thanks :)

    An idea. Never tried anything like this myself, so don't know if it will work. Don't see why it shouldn't though.
    A jar file is just a file in the zip format so write some code that uses the tools in java.util.zip to unpack the jar (or just specific contents) to somewhere like /temp
    Then use the runtime exec to start the browser with the argument /temp/file.html
    Hope this helps.

  • Stretching of HTML table in JLabel

    Hi all,
    I am trying to display an HTML table in a JLabel. The table uses width="100%", but the html table doesn't resize according to the size of the JLabel. Is this a know issue or am I doing something wrong?
      String html = "<html> <head> </head> <body> <table border=\"2\" width=100%> <tr> <td>  test  </td> <td> test </td> <td> test </td> </tr> </table> </body> </html>";
            JLabel label = new JLabel(html);
            getContentPane().add(label, BorderLayout.CENTER);kind regards,
    Christiaan

    The JTable uses a cell renderer to draw the JLabel.
    The cell renderer figures out the size of the table cell without reading the html. Which means it ignores the width=100% when it calculates the size of the table cell. If you want the cell to resize properly, you have to implement a table cell renderer, and make that renderer set the column size or row height accordingly. That means you have to calculate the cell size yourself.
    In my opnion, i would say this is a bug, as I've had numerous problems with it too.

  • Can i show an HTML text on JLabel

    Can any body help me about showing HTML text on a JLabel component!!
    Thanks.
    Neeraj

    http://forums.java.sun.com/thread.jsp?forum=57&thread=151899

  • HTML inside flash Movie

    How can i link and view any html page inside a flash movie,
    for example, i
    want to view a yahoo page inside of a movie... I apreciate
    all coments and
    help... Please!!!

    EFREN,
    > How can i link and view any html page inside a flash
    movie,
    > for example, i want to view a yahoo page inside of a
    movie...
    > I apreciate all coments and help... Please!!!
    I'm afraid you can't. If you were reading your HTML
    documents with a
    browser, that would be one thing. Browsers are HTML-reading
    machines. The
    Flash Player is not. The Flash Player reads Flash files.
    While Flash does
    support a modicum of the full HTML spec -- see "About
    supported HTML tags"
    in the documentation for details -- Flash does not, as a
    rule, open HTML
    documents.
    David
    stiller (at) quip (dot) net
    Dev essays:
    http://www.quip.net/blog/
    "Luck is the residue of good design."

  • HTML inside flash

    I am trying to display a html based weather widget inside a flash asctinscript 2 file using CS3.
    Can anyone point me to a tutorial on this?
    Forrest

    kglad, would it be possible for you to look at my other posting called,
    Loading a swf into a swf
    That is the proper forum for this discussion. I have posted my files there in a zip format.
    My yourwidget.fla (or in the my case, palm_springs_2.fla), has 2 scenes. When I use my loadMovie in my "Test load.fla", it loads the preload scene and not the main scene. However, when I remove the preload scene from palm_springs_2.fla it will not load the main scene content either.
    I am using an empty movieClip (with a instance name of "empty_mc") to load the incoming "palm_springs_2.swf" and using the code;
    empty_mc.loadMovie("palm_springs_2.swf");
    If I use "empty_mc.loadMovieNum("palm_springs_3.swf",1);", I get nothing at all.
    I know I am missing something. If you are able to look at this code I would really appreciate it.
    Forrest

  • Presenting binary file content as HTML inside a Portlet

    Hello folks,
    Do any of you has a piece of code that does that? Grabbing a word doc, pdf, ppt and such and convert it to HTML in order to present it inside a portlet? The easiest way would possibly be to use Dynamic Converter API, right? Is there any licensing problems on using Dynamic Converter on the limited UCM that comes with WebCenter Suite for that?
    Thanks In Advance,
    Pedro Boechat
    Edited by: pboechat on 28/08/2009 10:01

    Carmen,
    There patch available for this bug in metalink ( http://metalink.oracle.com ). You should find the patch in the recent portal patch list. The bug no for this patch is 1574770.

  • Html inside  Servlet

    Im trying to create a HTML page that will be created and invoked from a servlet.
    In order to do so, I created the HTML page in Frontpage 2003 and then added it to the Servlet code using [out.println(" ............");] for each and every statement
    Now, I dont get the output as I would get when the page is directly executed.Remember I calling /creating the HTML page from a servlet.
    I have the replaced the " with \" so that wont be an issue here. Also the Java Servlet code compiles without any error.
    1. Now where I face a problem is when I add the Java Script codes they dont execute. For example I created a button using FrontPage and set the 3 modes for it ,
    - on mouse over
    -On mouse down
    - on mouse up.
    So they created 3 different functions and added their own code to the HTML page.I managed to add all of it to the servlet.
    But the picture just refuses to load!
    2. Also, when I use a plain Html code like,
    out.println(" <input src=getdetails.gif name= \"image\" type=\"image\" tabindex=\"8\">");
    the pic doesnt load. On looking at the properties of the picture I dont see the location of the picture instead I see http://localhost:8080/examples/servlet/TestServlet.
    So Can someone please help me embed the Java Script code inside my servlet code and also show me how to use the code in point 2.
    Thank you.

    Well actually the .HTML file having the javascript code works perfectly. This file was created using Frontpage 2003.
    But, when I copy-paste the same thing in my .JAVA and supply the absolute paths for the images, something misfires and I dont get the same result.
    If you would like to have a peek at it , this is the line as in the .HTML File
    <input img border="0" id="img1" src="button5.jpg" height="20" width="100" type ="image" alt="Button Text" onmouseover="FP_swapImg(1,0,/*id*/'img1',/*url*/'button6.jpg')" onmouseout="FP_swapImg(0,0,/*id*/'img1',/*url*/'button5.jpg')" onmousedown="FP_swapImg(1,0,/*id*/'img1',/*url*/'buttonA.jpg')" onmouseup="FP_swapImg(0,0,/*id*/'img1',/*url*/'button6.jpg')" fp-style="fp-btn: Braided Column 3" fp-title="Button Text"></p>Now when I transfer it to the .JAVA file it becomes like this.
    pw.println("<input img border=\"0\" id=\"img1\" src=\"c:\\Images\\button5.jpg\" height=\"20\" type =\"image\" width=\"100\" alt=\"Book Flight\" onmouseover=\"FP_swapImg(1,0,/*id*/'img1',/*url*/\"C:\\Images\\button6.jpg\")\" onmouseout=\"FP_swapImg(0,0,/*id*/'img1',/*url*/\"C:\\Images\\button5.jpg\")\" onmousedown=\"FP_swapImg(1,0,/*id*/'img1',/*url*/\"C:\\Images\\buttonA.jpg\")\" onmouseup=\"FP_swapImg(0,0,/*id*/'img1',/*url*/\"C:\\Images\\button6.jpg\")\" fp-style=\"fp-btn: Braided Column 3; fp-font-size: 11; fp-font-color-hover: #FF0000; fp-font-color-press: #0000FF\" fp-title=\"Book Flight\"></p>");Can someone throw some light as to whats ,/*url*/ and do I still need to keep it in the code.
    Thank you.

  • New line inside a JLabel

    I know that this sounds like a noobie question but....
    I created a JLabel that has a paragraph in it. When I run the program, it prints the paragraph in one line. How do I make it so I can insert new lines? Since this is a GUI, I can't use println. I've tried the following:
    Code:
    JLabel label = new JLabel("BLAH BLAH BLAH BLAH BLAH BLAH BLAH\n" +
    "BLAH BLAH BLAH BLAH BLAH BLAH BLAH");
    The "\n" doesn't work either. Help pl x?
    --------------------------------------------------------------------------------

    <html>blah blah <br>blah balah
    (Swing in the Swing forums).

  • How to disable html view in JLabel

    "As of Swing 1.1.1 Beta 1, JLabel supports multiple lines, multiple fonts, and a whole lot more because you can specify a label's text using HTML. "
    does any one know how to disable this feature, so that if HTML code is entered, it wont be parsed andwhat ever was entered will be displayed, as is, on the JLabel????

    I dont really have control of what is being entered.Whose program is it, then, that contains the setText() method for the JLabel? (Or creates a JLabel with some text?) If it's yours, then I don't see why you can't examine the text before you call that line of code and modify the text as suggested earlier.

Maybe you are looking for

  • How to switch back to old depreciation calc method during upgrade to ECC6.0

    Hi Everyone, We are doing a technical upgrade from 4.6C to ECC 6.0 and we have activated the enterprise extension EA-FIN via SWF5 (switch framework) to use the functionality of accrual engine, closing cockpit etc. However, activating EA-FIN has activ

  • Using target mode and g4 to restore my time machine on my imac? help

    I have a imac 27" intel 10.6 that became  stuck on grey screen, Tried everything. problem dont have original cd install cd snow Leopard 10.6... so I used target mode from a g4 10.4 mac and erased data on my imac then went into the disk utility and dr

  • SCCM Console, untrusted forest

    Hi, I have a site system server with MP, DP in a untrusted forest. Is it possible to install SCCM console on it and connect back to Primary server? I have checked all ports that are in the documentation https://technet.microsoft.com/en-us/library/hh4

  • Send mail in a certain way

    Hello: I need to send emails by groups including some magazine with Director, like magazine GamaSutra Daily. It seems like a web page inserted in the client mailing software (outlook Express,...) Can you tell me how to do this with Lingo, please? Tha

  • Problems with Advanced Queueing...

    Hi, Has anyone used AQ through OCI? We are having problems with OCISubscriptionRegister() the error reported back is 'two task conversions - overflow integer'. The code we are running is straight out of the published demos... Please HELP!! Thanks, Da