Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!transit3.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail From: "Andrew Thompson" Subject: Re: HTML in JTree (via JE Message-ID: <73a0a7ca1bf2a@uwe> X-Comment-To: comp.lang.java.gui Newsgroups: comp.lang.java.gui In-Reply-To: References: Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92] Lines: 73 Date: Wed, 27 Apr 2011 15:35:32 GMT NNTP-Posting-Host: 96.60.20.240 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1303918532 96.60.20.240 (Wed, 27 Apr 2011 10:35:32 CDT) NNTP-Posting-Date: Wed, 27 Apr 2011 10:35:32 CDT Organization: TDS.net Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:1819 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.. import javax.swing.*; import java.awt.BorderLayout; class BigRedText { public static void main(String[] args) { String message1 = "Big Red Text"; String message2 = "Big " + "Red
Text"; JPanel mainPanel = new JPanel( new BorderLayout() ); JLabel labelNoHTML = new JLabel(message1); mainPanel.add( labelNoHTML, BorderLayout.NORTH ); JLabel labelAsHTML = new JLabel("" + 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("" + message2 ); mainPanel.add( labelWithHTML, BorderLayout.SOUTH ); JOptionPane.showMessageDialog(null, mainPanel); } }
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