-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.4.1
-
x86
-
windows_2000
Name: rmT116609 Date: 03/20/2003
FULL PRODUCT VERSION :
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
FULL OS VERSION :
ver Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
I started working on creating customised JSpinner editing format. As and when user types values like 1000, it should appear like 10.00. I could achieve the same using KeyListener implementation. I figured out that cursor's ZEROth (0) position is on left most side. So when user wants to type and see the value of 1235, it comes as 53.21 which is not acceptable for our required business logic. So I tried setting the caret position to the lenght of the text value of JFormattedTextField (Which is used by JSpinner) and the length should be right most position of the JSpinner. I guess it is a bug in the JSpinner which does not accept the setting of cursor position. Because, even after setting the position, if user types some value, it comes back to ZERO th position i.e. left most. Below in the "Source code for an executable test case:" section, I have pasted the code.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the above mentioned program which is pasted in the "Source code for an executable test case:" section. Compile the Java program and run the same.
EXPECTED VERSUS ACTUAL BEHAVIOR :
As soon as spinner is constructed, the cursor should appear to the right side of the ZERO (0 - Initial value) value.
The cursor appears to the left side of ZERO (0 - Initial value) value
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/*
* NewTestSpinner.java
*
* Created on March 7, 2003, 2:21 PM
*/
import javax.swing.*;
import javax.swing.JSpinner.*;
import javax.swing.event.*;
import java.text.*;
import javax.swing.text.JTextComponent.*;
import java.awt.*;
import java.util.*;
import java.awt.event.KeyListener;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.FocusEvent;
import java.lang.String;
import javax.swing.JFormattedTextField.AbstractFormatter;
import javax.swing.text.NavigationFilter.FilterBypass;
import javax.swing.text.Position.Bias;
public class NewTestSpinner implements KeyListener {
JFrame frame = new JFrame("Spinner");
SpinnerNumberModel priceModel = new SpinnerNumberModel(0,0,5000000.00,5);
JSpinner qParam= new javax.swing.JSpinner(priceModel);
Double db1;
double db2 = 0.00;
Double db3;
String st1=null;
boolean valuExists = false;
String str2=null;
/** Creates a new instance of NewTestSpinner */
public NewTestSpinner() {
qParam.setEditor(new javax.swing.JSpinner.NumberEditor(qParam,"#####.##" ));
frame.setDefaultCloseOperation(3);
frame.getContentPane().add(qParam, BorderLayout.CENTER);
/**To set the cursor position to the right most*/
((JSpinner.DefaultEditor)qParam.getEditor()).getTextField().setCaretPosition(((JSpinner.DefaultEditor)qParam.getEditor()).getTextField().getText().length());
((JSpinner.DefaultEditor)qParam.getEditor()).getTextField().addKeyListener(this);
frame.pack();
frame.show();
}
/**Required Logic to put the value in the format*/
public void keyPressed(java.awt.event.KeyEvent e) {
}
/**When the typed value key is released, value of text is taken,
*convrted into double, then divided and put back into the text.*/
public void keyReleased(java.awt.event.KeyEvent e) {
}
public void keyTyped(java.awt.event.KeyEvent e) {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new NewTestSpinner();
}
}
---------- END SOURCE ----------
(Review ID: 182447)
======================================================================