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
Optional Replicator mirror
Your face IP:[184.108.40.206]
You are visitor number|