JTextField selectAll() And DefaultCellEditor

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading ... Loading ...

I am guessing this is quite a common problem that programmers encounter when they have JTextField objects inside a JTable. When you click on a cell, it would not select all the text in it. You have to double click it first. Even the DefaultCellEditor’s setClickCountToStart(1) method does not help. The workaround for this is to override the shouldSelectCell() method.

1
2
3
4
5
@Override
public boolean shouldSelectCell(EventObject eo) {
    ((JTextField) getComponent()).selectAll();
    return super.shouldSelectCell(eo);
}
Bookmark and Share

Found this post useful? Buy me a cup of coffee or help support the sponsors on the right.

Related Posts with Thumbnails

One Response to “JTextField selectAll() And DefaultCellEditor”

  1. 1
    Rizky2009 Says:

    sayangnya aq g bisa bahasa inggris… jadi bingung harus coment apa…

Leave a Reply