You can embed HTML in the text of a JLabel to get a multi-line JLabel. This is the easiest way to get a multi-line label. The main drawback is using it causes the entire HTML-rendering mechanism to be loaded. Also sometimes JLabels mysteriously reshape themselves to tall skinny rectangles with only a few words per line. This technique thanks to a tip from Eitan Rosenberg:
You can use a JTextArea to fake a multi-line JLabel. Set the background colour to the body colour of the whole application to simulate transparency.
// fake multi-line JLabel with JTextArea final JTextArea jta = new JTextArea(); jta.setFont( new Font( "Dialog", Font.PLAIN, 12 ) ); jta.setForeground( FOREGROUND_FOR_INSTRUCTIONS ); jta.setBackground( BACKGROUND_FOR_BODY ); jta.setEditable( false ); jta.setBorder( BorderFactory.createEmptyBorder() ); jta.setText( "line1\nline2");
You can embed <br> and other simple HTML markup with a JEditorPane like this:
Unfortunately, Oracle does not document just what features of HTML are supported. I discovered by experiment the entity ⇒ is not supported. The renderer does not insist on <body>…</body> tags. I have discovered that JEditorPanes accept <style commands. I have written Oracle asking them to clarify.
This page is posted |
http://mindprod.com/jgloss/jlabel.html | |
Optional Replicator mirror
|
J:\mindprod\jgloss\jlabel.html | |
Please read the feedback from other visitors,
or send your own feedback about the site. Contact Roedy. Please feel free to link to this page without explicit permission. | ||
Canadian
Mind
Products
IP:[65.110.21.43] Your face IP:[3.128.31.227] |
| |
Feedback |
You are visitor number | |