Selection overridden by formatter
Question
I have applied a Formatter
to a JFormattedTextField
using a FormatterFactory
, when a user clicks into the text field I want to select the contents.
A focus listener does not work as expected because the formatter gets called, which eventually causes the value to be reset which ultimately de-selects the fields contents. I think what is happening is that after the value changes, the Caret moves to the rightmost position and this deselects the field.
Does anyone have any knowledge of how to get around this and select the fields contents correctly?
Solution
Quick and dirty workaround is to use EventQueue.invokeLater from your focusListener.
EventQueue.invokeLater(new Runnable(){
public void run() { yourTextField.selectAll();}
});
OTHER TIPS
which jdk are you using - any chance this is a bug in it?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow