Q:

Table cell editor does show editing cursor when called editCellAt

I have a dialog which contains a table. The requirement is to show a cell in editable mode when dialog is showing. Following is the code
class MyDialog extends JDialog
{
    JTable tbl = new JTable(new Object[][]{new String[]{"a", "b"}, new String[]{"1", "2"}},  new String[]{"col1", "col2"});    

    public MyDialog(Frame frame)
    {
        add(tbl);
        setSize(300, 300);

        tbl.setCellEditor(new DefaultCellEditor(new JTextField()));
    }

    @Override
    public void setVisible(boolean b)
    {
        super.setVisible(b);
        if(b)
        {
            tbl.editCellAt(tbl.getRowCount() - 1, tbl.getColumnCount() - 1);
        }
    }
}

Following is the way to show
MyDialog d = new MyDialog(parent);
d.setLocationRelativeTo(btn);
d.setVisible(true);

Problem is even the cell is in the edit mode the cursor does not appear in the text field until user click. But the text can be typed.
Any thing missing or wrong in this code?

A:

Calling setVisible doesn't make the window suddenly visible, but instead, schedules the window to become visible at some point the future.
You could use a combination of requestFocusInWindow and SwingUtilities#invokeLater to request that the cell editor be given focus at some point the future, for example...
@Override
public void setVisible(boolean b) {
    super.setVisible(b);
    if (b) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                tbl.editCellAt(tbl.getRowCount() - 1, tbl.getColumnCount() - 1);
                tbl.getEditorComponent().requestFocusInWindow();
            }
        });
    }
}

I'd also be tempted not to override setVisible but instead use a WindowListener, but that's me

