Name: skT88420 Date: 07/21/99
/*
Program to illustrate the caret bug.
Typing into an unfocussed cell fails to transfer the focus to
the cell editor.
To reproduce, run this program. Click into any cell a single
time. A caret will not appear. At this point, the cell has a
colored outline, indicating that the JTable has the focus,
rather than the cell editor. So the caret should not be
visible yet.
Now, start typing. The cell outline will change to black,
indicating that the focus has shifted to the cell editor.
The text will appear as I type, but the caret is still
missing. By now, it is clear that there is a bug.
The caret should always be visible during typing.
It appears that, even though the cell is outlined in black,
and I can type into the cell, it still doesn't have the focus.
You can see this by hitting an arrow key. The focus will move
to a different cell, rather than changing the caret position.
This shows that the cell editor doesn't actually have the
focus, as it should.
Once I have started typing, I can click into the cell, and the
caret will finally appear. Now the arrow keys will move the
caret.
This behavior is discussed in bug 4188907. That bug was
erroneously closed. Please reopen that bug, rather than
creating a new bug. I don't want to lose the votes this bug
has already accumulated.
*/
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.awt.event.*;
public class JTableFocusBug
{
public static void main(String[] args)
{
JFrame mf = new JFrame("Caret in JTable Bug");
WindowListener wl = new WindowAdapter()
{
public void windowClosing(WindowEvent evt) { System.exit(0); }
};
mf.addWindowListener(wl);
mf.setBounds(10, 10, 400, 400);
JScrollPane scroller = new JScrollPane(new JTable(new BugModel()));
mf.getContentPane().add(scroller);
mf.show();
}
private static class BugModel extends AbstractTableModel
{
public int getRowCount() { return 3; }
public int getColumnCount() { return 3; }
public Object getValueAt(int row, int col) { return "" /* + row + ", " + col*/; }
BugModel() { super(); }
public boolean isCellEditable(int row, int col)
{
return true;
}
}
}
(Review ID: 88158)
======================================================================