Results 1 to 5 of 5
- 06-07-2007, 05:16 PM #1
- 06-07-2007, 05:18 PM #2
Member
- Join Date
- May 2007
- Posts
- 8
- Rep Power
- 0
You could just try setting the string text to what you want, and use the \n command to break the lines up.
ie.
Java Code:String str = "This is \nmy example \nof a multi-line \nJLabel"; JLabel strLabel = new JLabel (str);
- 06-07-2007, 05:19 PM #3levent Guest
Java Code:import java.awt.*; import javax.swing.*; public class MultilineLabel { public static void main(String[] args) { String str = "This is \nmy example \nof a multi-line \nJLabel"; JLabel strLabel = new JLabel (str); display(strLabel, "Hmmm..."); } public static void display(JComponent comp, String title) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(comp); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); } }
- 02-05-2009, 10:26 PM #4
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
I know this is an old thread, but, since the original poster did not followup, I copied and pasted the code given by levent into NetBeans and ran it. The newlines did NOT appear in the label. Perhaps this worked circa June, 2007, but it doesn't work with Java SE 6.10.
Edit:
goto velocityreviews forums multiline-jlabel (wasn't allowed to include link)
shows how to do this using HTML. one is to use only html formatting including <br> in place of \n, another is to use standard C-format codes and use the <pre></pre> tags.Last edited by mikeeve; 02-13-2009 at 12:33 AM.
- 12-14-2009, 05:09 AM #5
Member
- Join Date
- Dec 2009
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
Method to write if the string object can be converted to Integer or not.
By Abhishek in forum New To JavaReplies: 4Last Post: 03-25-2008, 12:16 PM -
Finding the exact length of a string in a JLabel (in pixels)
By Clarkey in forum Advanced JavaReplies: 2Last Post: 03-25-2008, 05:49 AM -
Problems with JLabel 2
By geork in forum New To JavaReplies: 2Last Post: 02-03-2008, 08:40 PM -
JLabel
By Jack in forum AWT / SwingReplies: 2Last Post: 07-02-2007, 01:55 PM -
JLabel
By Freddie in forum AWT / SwingReplies: 2Last Post: 05-29-2007, 02:19 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks