-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.4.2
-
x86
-
windows_2000
Name: rmT116609 Date: 02/12/2004
FULL PRODUCT VERSION :
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
There are actually two related issues here:
First, calling setEditable(false) on a JTextField or JTextArea causes the cursor to become a Cursor.DEFAULT_CURSOR, regardless of what the cursor was set before the method was called. Second, setEditable(false) also causes the background color of the JTextField to change to grey.
This seems very odd to me. A JTextComponent's's "editablity" should be independent of its cursor and background color. The method is called "setEditable()", not "setEditableAndCursor()" or "setEditableAndCursorAndBackground().
As I mentioned, with a JTextField it's not only the cursor that changes but also the background color.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See "Source code" section below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I believe the prober behavior is for "setEditable(false)" to do as the method says -- make the field not editable. It should have no effect on the field's background color or its cursor.
ACTUAL -
see "Description" section above.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.Cursor;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Tester2 {
public static void main(String[] args) {
JFrame f = new JFrame();
f.getContentPane().setLayout(new FlowLayout());
JTextArea textArea = new JTextArea(10, 20);
JTextField textField = new JTextField(10);
f.getContentPane().add(textArea);
f.getContentPane().add(textField);
textArea.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
textField.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
textArea.setEditable(false);
textField.setEditable(false);
// Uncomment these two lines to restores the cursors
// textArea.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
// textField.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
f.pack();
f.setVisible(true);
}
}
---------- END SOURCE ----------
(Incident Review ID: 235887)
======================================================================
- duplicates
-
JDK-4851758 Uneditable text components should inherit their parent's cursor.
-
- Resolved
-