Long text in JLabel

Hy,I have very long text and I want to put it without wrapping in JLabel. What should I do?Thanks!
[126 byte] By [mustheroa] at [2007-11-27 9:47:45]
# 1
Set the PreferredSize of the JLabel. This might however affect your layout depending on how things are laid out in your container.ICE
icewalker2ga at 2007-7-13 0:00:32 > top of Java-index,Desktop,Core GUI APIs...
# 2
I don't the size. The text will be added in real-time.
mustheroa at 2007-7-13 0:00:32 > top of Java-index,Desktop,Core GUI APIs...
# 3

Then you need to determine the width of the String content

JLabel label = new JLabel("Some text");

FontMetrics fm = label.getGraphics().getFontMetrics(label.getFont());

int strWidth = (int)fm.getStringBounds(label.getText(), g).getWidth();

label.setPreferredSize( new Dimension(strWidth + 10, 20) );

ICE

icewalker2ga at 2007-7-13 0:00:32 > top of Java-index,Desktop,Core GUI APIs...
# 4
What is variable "g" in your code? It's not defined :(
mustheroa at 2007-7-13 0:00:32 > top of Java-index,Desktop,Core GUI APIs...
# 5
I did, but labels are still wrapped. :(((
mustheroa at 2007-7-13 0:00:32 > top of Java-index,Desktop,Core GUI APIs...
# 6

> but labels are still wrapped.

Labels do not wrap.

If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",

see http://homepage1.nifty.com/algafield/sscce.html,

that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the "Code Formatting Tags",

see http://forum.java.sun.com/help.jspa?sec=formatting,

so the posted code retains its original formatting.

camickra at 2007-7-13 0:00:32 > top of Java-index,Desktop,Core GUI APIs...