-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.3.0, 1.3.1
-
generic, x86
-
generic, windows_nt
Name: skT45625 Date: 05/10/2000
java -version
java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)
JTextArea.getPreferredSize returns results that seem to work differently from
what the renderer for the object are expecting, and so, anamolous pictures
result. I have not looked at any of the rendering code, to see if this is
exactly what is wrong, but the behavior seems to confirm the connection.
Another way to state this, is getPreferredSize does not return the actual size
used by the renderer to paint the component when the other sides are messed up.
Compile and run the accompanying code. It creates 4 Frames, the first frame "No
Border" renders fine, the second frame "with border" does not. The accompanying
lower button is hidden, because with the border included, the rendering code (I
believe, I've not looked at it in detail) thinks it needs an additional row,
over what getPreferredSize indicated.
The frame "My Fix" shows how getPreferredSize can be fixed for this part of the
problem.
However, the frame "Another Problem" shows that the problems of the function are
deeper than what I've just indicated, because, again, the button is rendered off
the bottom of the visible part of the frame, because the preferred number of
rows is wrong given the text contained within.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JTextAreaBug {
public static void setupFrame(JTextArea text, String title) {
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
mainPanel.add(text);
mainPanel.add(new JButton("Button"));
final JFrame frame = new JFrame(title);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);};
});
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setVisible(true);
};
public static void main (String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
byte[] bytes = new byte[120*4-1];
for (int i = 0; i < 119; i++) {
bytes[i + 3 * 120] = (byte)((i%10) + 48);
bytes[i + 120] = 'M';
bytes[i + 2 * 120] = '!';
bytes[i] = (byte)((i%10) + 48);
};
bytes[119] = '9';
bytes[239] = 'M';
bytes[359] = '!';
String text = new String(bytes, 0, bytes.length, "ASCII");
JTextArea textArea1 = new JTextArea(text, 4, 120);
textArea1.setLineWrap(true);
textArea1.setFont(new Font("Courier", Font.PLAIN, 14));
setupFrame(textArea1, "No Border");
JTextArea textArea2 = new JTextArea(text, 4, 120);
textArea2.setLineWrap(true);
textArea2.setFont(new Font("Courier", Font.PLAIN, 14));
textArea2.setBorder(BorderFactory.createLoweredBevelBorder());
setupFrame(textArea2, "With Border");
MyJTextArea textArea3 = new MyJTextArea(text, 4, 120);
textArea3.setLineWrap(true);
textArea3.setFont(new Font("Courier", Font.PLAIN, 14));
textArea3.setBorder(BorderFactory.createLoweredBevelBorder());
setupFrame(textArea3, "My Fix");
JTextArea textArea4 = new JTextArea(text, 4, 119);
textArea4.setLineWrap(true);
textArea4.setFont(new Font("Courier", Font.PLAIN, 14));
setupFrame(textArea4, "Another Problem");
};
};
class MyJTextArea extends JTextArea {
MyJTextArea(String text, int rows, int columns) {
super(text,rows,columns);
};
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
Insets insets = getBorder().getBorderInsets(this);
return new Dimension(d.width + insets.left + insets.right,
d.height + insets.top + insets.bottom);
};
};
(Review ID: 103226)
======================================================================
- relates to
-
JDK-4307595 After AbstractButton.setBorderPainted(true) call button's label looks incorrectl
-
- Closed
-