JTextField selectAll() And DefaultCellEditor


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);
}

Found this post useful? Buy me a cup of coffee or subscribe to my RSS feeds and Google Friend Connect

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

Spam protection by WP Captcha-Free