In all the examples that I can find that use a JTextArea, the height & width is known before constructing the JTextArea, and if the JText
import java.awt.*;
import javax.swing.*;
class FixedWidthLabel {
public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
String pt1 = "Label Height
" +
"Many Swing components support HTML 3.2 &" +
" (simple) CSS. By setting a body width we can cause the " +
" component to find the natural height needed to display" +
" the component.
" +
"
The body width in this text is set to " +
"";
String pt3 =
" pixels." +
"";
JPanel p = new JPanel( new BorderLayout() );
JLabel l1 = new JLabel( pt1 + "125" + pt2 + "125" + pt3 );
p.add(l1, BorderLayout.WEST);
JLabel l2 = new JLabel( pt1 + "200" + pt2 + "200" + pt3 );
p.add(l2, BorderLayout.CENTER);
JOptionPane.showMessageDialog(null, p);
}
};
SwingUtilities.invokeLater(r);
}
}