-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
6
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
On a freshly created and initialized JFormattedTextField, setCaretPosition and select have no visible effect, although enquiring programmatically about the caret position or the selection after changing either returns the expected result: somehow the model processed the command but the view did not reflect it.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Call the program below with all combinations of inputs and observe the results.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JFormattedTextField should behave the same as JTextField
ACTUAL -
See problem description.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
public class Bug35 {
public Bug35(boolean formatted, boolean select, String title, int pos) {
JTextField jt = formatted ?
createFormattedTextField() : createTextField();
show(jt, title, pos);
if (select) {
jt.select(2, 5);
printInfo(jt); } else {
jt.setCaretPosition(3);
printInfo(jt); }
}
private JTextField createTextField() {
JTextField jt = new JTextField();
jt.setText("123456789");
return jt;
}
private JTextField createFormattedTextField() {
JFormattedTextField jt = new JFormattedTextField();
jt.setValue(new Integer(123456789));
return jt;
}
private void show(JComponent jc, String title, int pos) {
JFrame jf = new JFrame();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setTitle(jc.getClass().getName());
jf.getContentPane().add(jc);
jf.pack();
jf.setSize(200, 50);
jf.setLocation(50, pos);
jf.setVisible(true);
}
private void printInfo(JTextField jt) {
System.out.println(jt.getCaretPosition() + ", " + jt.getSelectionStart() + "-" + jt.getSelectionEnd());
}
public static final void main(String[] argv) {
Bug35 app = new Bug35(true, false, "JFormattedTextField w/out Select", 0);
app = new Bug35(false, false, "JTextField w/out Select1", 50);
//comment & uncomment the following 2 statements to see the differences
//when select is made between JFormattedTextField & JTextField
app = new Bug35(true, true, "JFormattedTextField w/ Select", 150);
//app = new Bug35(false, true, "JTextField w/ Select", 150);
}
}
---------- END SOURCE ----------
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
On a freshly created and initialized JFormattedTextField, setCaretPosition and select have no visible effect, although enquiring programmatically about the caret position or the selection after changing either returns the expected result: somehow the model processed the command but the view did not reflect it.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Call the program below with all combinations of inputs and observe the results.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JFormattedTextField should behave the same as JTextField
ACTUAL -
See problem description.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
public class Bug35 {
public Bug35(boolean formatted, boolean select, String title, int pos) {
JTextField jt = formatted ?
createFormattedTextField() : createTextField();
show(jt, title, pos);
if (select) {
jt.select(2, 5);
printInfo(jt); } else {
jt.setCaretPosition(3);
printInfo(jt); }
}
private JTextField createTextField() {
JTextField jt = new JTextField();
jt.setText("123456789");
return jt;
}
private JTextField createFormattedTextField() {
JFormattedTextField jt = new JFormattedTextField();
jt.setValue(new Integer(123456789));
return jt;
}
private void show(JComponent jc, String title, int pos) {
JFrame jf = new JFrame();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setTitle(jc.getClass().getName());
jf.getContentPane().add(jc);
jf.pack();
jf.setSize(200, 50);
jf.setLocation(50, pos);
jf.setVisible(true);
}
private void printInfo(JTextField jt) {
System.out.println(jt.getCaretPosition() + ", " + jt.getSelectionStart() + "-" + jt.getSelectionEnd());
}
public static final void main(String[] argv) {
Bug35 app = new Bug35(true, false, "JFormattedTextField w/out Select", 0);
app = new Bug35(false, false, "JTextField w/out Select1", 50);
//comment & uncomment the following 2 statements to see the differences
//when select is made between JFormattedTextField & JTextField
app = new Bug35(true, true, "JFormattedTextField w/ Select", 150);
//app = new Bug35(false, true, "JTextField w/ Select", 150);
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-6567411 Unable programmatically select text in JFormattedTextField
-
- Open
-