RFR: 5032471: JFormattedTextField does not use editformatter on initial focus with setText() [v2]
Alexey Ivanov
aivanov at openjdk.org
Fri Jul 28 19:43:54 UTC 2023
On Wed, 26 Jul 2023 03:27:41 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:
>> When a JFormattedTextField field value is set by setText, then when the field initially gains focus it seems to not use the edit formatter, but rather use display formatter, which is wrong.
>> Native "Date and Time setting" in windows changes the date field to edit mode in initial focus itself.
>> Fix is made to treat setText as in edit mode and commit the changes made to it.
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
>
> setDocument and test fix
I wonder what happens if `setText` is called with a value that cannot be interpreted by the current formatter and how it plays with different policies on focus lost as outlined in [the javadoc](https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/JFormattedTextField.html).
src/java.desktop/share/classes/javax/swing/JFormattedTextField.java line 746:
> 744: //do nothing, we assume this will never happen.
> 745: }
> 746: }
Since the same piece of code is needed in two different methods, it should be moved into a new helper method. It avoids duplication and therefore possible inconsistency because only one place is updated.
test/jdk/javax/swing/JFormattedTextField/JFormattedTextProblem.java line 36:
> 34: import java.awt.event.KeyEvent;
> 35: import java.beans.PropertyChangeEvent;
> 36: import java.beans.PropertyChangeListener;
Could you sort the imports and remove the unused ones?
test/jdk/javax/swing/JFormattedTextField/JFormattedTextProblem.java line 51:
> 49: import java.text.SimpleDateFormat;
> 50:
> 51: public class JFormattedTextProblem {
Should we use a more descriptive name for the test class?
test/jdk/javax/swing/JFormattedTextField/JFormattedTextProblem.java line 101:
> 99:
> 100: DateFormat displayTime = DateFormat.getTimeInstance(DateFormat.MEDIUM);
> 101: SimpleDateFormat editTime = new SimpleDateFormat("HH:mm");
These two variables are unused, should we remove them?
-------------
Changes requested by aivanov (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/14993#pullrequestreview-1552508827
PR Review Comment: https://git.openjdk.org/jdk/pull/14993#discussion_r1277786500
PR Review Comment: https://git.openjdk.org/jdk/pull/14993#discussion_r1278001641
PR Review Comment: https://git.openjdk.org/jdk/pull/14993#discussion_r1278016892
PR Review Comment: https://git.openjdk.org/jdk/pull/14993#discussion_r1278000797
More information about the client-libs-dev
mailing list