Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #1819

Re: HTML in JTree (via JE

From "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this>
Subject Re: HTML in JTree (via JE
Message-ID <73a0a7ca1bf2a@uwe> (permalink)
Newsgroups comp.lang.java.gui
References <f4o4rh$sl1$1@sagnix.uni-muenster.de>
Date 2011-04-27 15:35 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
Johannes Schwall wrote:
..
>My problem is, that I do not really understand how to create a node that is
>not only a node, but has the ability described before (text with
>linebreaking and the possibility to format parts of the text).

How does the new renderer understand where to
put the breaks?  What formats to use?

>Something like the following would produce a normal node, which would
>probably use a JLabel (I guess that's the default behaviour).
..
>I did not test this yet. But if I remember correctly, I had difficulties
>using HTML inside the node like this. 

Perhaps it is better to break the problem into parts..
- How to get a JComponent to display HTML
- How to get the renderer to understand the HTML
formatting that needs to be performed.
- How to get JTree to use the component.

>...Thus my thrive to use some different
>element, e.g. JEditorPane for the HTML rendering.

JEP would also be possible, but its default behaviour
is to allow editing, and it has many features not required
to simply render HTML.

In any case, you were on the right track with your 
example, hopefully this will get you further..
<sscce>
import javax.swing.*;
import java.awt.BorderLayout;

class BigRedText {

  public static void main(String[] args) {
    String message1 = "Big Red Text";

    String message2 = "<font size='+2'>Big</font> " +
      "<font color='red'>Red</font><br>Text";
    JPanel mainPanel = new JPanel( new BorderLayout() );

    JLabel labelNoHTML = new JLabel(message1);
    mainPanel.add( labelNoHTML, BorderLayout.NORTH );

    JLabel labelAsHTML = new JLabel("<html><body>" + message1);
    mainPanel.add( labelAsHTML, BorderLayout.CENTER );
    // ..it looks EXACTLY the same (why wouldn't it?)

    // Now our String with HTML formatting
    JLabel labelWithHTML = new JLabel("<html><body>" + message2 );
    mainPanel.add( labelWithHTML, BorderLayout.SOUTH );

    JOptionPane.showMessageDialog(null, mainPanel);
  }
}
</sscce>

HTH

-- 
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-gui/200706/1

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: HTML in JTree (via JE "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:35 +0000
  Re: HTML in JTree (via JE "Tom Hawtin" <tom.hawtin@THRWHITE.remove-dii-this> - 2011-04-27 15:35 +0000
    Re: HTML in JTree (via JE "Johannes Schwall" <johannes.schwall@THRWHITE.remove-dii-this> - 2011-04-27 15:35 +0000
      Re: HTML in JTree (via JE "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:35 +0000
        Re: HTML in JTree (via JE "Johannes Schwall" <johannes.schwall@THRWHITE.remove-dii-this> - 2011-04-27 15:35 +0000
          Re: HTML in JTree (via JE "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:35 +0000
            Re: HTML in JTree (via JE "Johannes Schwall" <johannes.schwall@THRWHITE.remove-dii-this> - 2011-04-27 15:35 +0000
              Re: HTML in JTree (via JE "Johannes Schwall" <johannes.schwall@THRWHITE.remove-dii-this> - 2011-04-27 15:35 +0000
                Re: HTML in JTree (via JE "preetam.purbia" <preetam.purbia@THRWHITE.remove-dii-this> - 2011-04-27 15:36 +0000
                Re: HTML in JTree (via JE "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:36 +0000

csiph-web