Hello, if the text in the JTextField is not the default size, it appears that the field does not resize properly. Here is an example: on the left is the field with default size (height 12 for my look and feel - metal on XP) "80", and on the right, the same with size 11. If you click in between 8 and 0 and delete the 0 and insert something in its place, the 8 will move a little out of the field and it will look like a "3" - only in the field with non-default size though (and it is smaller too, which should make it "easier" to enclose).
How can I have smaller size and still resize properly?? Here is the code - isolated to the minimum possible, compiles and runs
import javax.swing.*;
import javax.swing.event.*;
public class Foobar
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
JPanel panel = new JPanel();
frame.setContentPane(panel);
FoobarTxtField normal = new FoobarTxtField("80");
panel.add(normal);
FoobarTxtField small = new FoobarTxtField("80");
small.setFont(small.getFont().deriveFont((float)11));
panel.add(small);
frame.pack();
frame.setVisible(true);
}
}
class FoobarTxtField extends JTextField implements DocumentListener
{
FoobarTxtField(String s)
{
super(s);
getDocument().addDocumentListener(this);
}
public void insertUpdate(DocumentEvent e)
{
SwingUtilities.getRootPane(this).revalidate();
}
public void removeUpdate(DocumentEvent e)
{
}
public void changedUpdate(DocumentEvent e)
{
}
}