-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
1.3.0
-
generic
-
generic
Name: rl16235 Date: 06/27/2000
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
When using JLabel with HTML text with no <br> or <p> tags, by default JLabel
try to put all the text on only one line. I usually want a long text to be
wrapped on multi lines. I can use "JComponent.setPreferredSize(Dimension)" to
specify on smaller size, but it is not possible to specified a preferred width
only and lets JLabel choose the best height. The following code illustrate it:
import java.awt.*;
import javax.swing.*;
public class Test
{
public static void main(String[] args)
{
JFrame frame=new JFrame("preferredSize unset");
JLabel label=new JLabel("<html>There is a long label. Do you know the
story about the guys in a bar who want to be bla bla bla...</html>");
frame.getContentPane().add(label);
frame.setLocation(10,10);
frame.pack();
frame.show();
frame=new JFrame("preferredSize set");
label=new JLabel("<html>There is a long label. Do you know the story
about the guys in a bar who want to be bla bla bla...</html>");
label.setPreferredSize(new Dimension(250,250));
frame.getContentPane().add(label);
frame.setLocation(60,60);
frame.pack();
frame.show();
}
}
If I can't use "setPreferredSize" because I don't want to set a height, I could
use "setMaximumSize" instead and hope that JLabel will chose the smallest
height capable to display the label fully. But JLabel seem to
ignore "setMaximumSize". It would be helpful if one of those two possibilities
was available:
1) Define a "JLabel.setPreferredWidth(int)" which allow us to set a width and
lets JLabel choose the best height matching it, or
2) Make "setMaximumSize" to work on JLabel.
Thanks.
(Review ID: 106581)
======================================================================