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
> 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.