JDK-4229456 : JTextField.setEnabled(false) doesn't remove component from focus list
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.7,1.2.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1999-04-14
  • Updated: 2001-04-18
  • Resolved: 2001-04-18
Related Reports
Duplicate :  
Description

Name: krT82822			Date: 04/14/99


When you call setEnabled(false) on any component the focus
manager should not allow you to tab to that component.

Example:

JTextField tf = new JTextField ("Test");
tf.setEnabled (false);

If tf is in a dialog with other Text Fields, then I can tab to
all text fields includeing tf whether or not it is enabled.
(Review ID: 56953) 
======================================================================

Name: vi73552			Date: 06/18/99


In our project We programatically set some Jtextfields to be disabled
with the purpose of avoiding entering of  those values contained by them 
frequently, giving it a different color(yellow). But sometimes when we backspace (keylistener 
transfer's focus to previous component) we are allowed to enter to previous component which is disabled.
Because we are allowed to enter disabled Jtextfield we are able to delete the values contained by these JTextfields.
This is quite annoying to us and we had to programmatically consider the case of JTextfield getting focus when it is disabled.


Our project is for TAB ltd which is multinational gambling company. The project is for Customers betting through phone.
(Review ID: 84505)
======================================================================

Comments
WORK AROUND Name: krT82822 Date: 04/14/99 The workaround is to manually set the next focus component as items become enabled and disabled. This involves quite a bit of coding intervention that I'd rather not have to do. ====================================================================== Name: vi73552 Date: 06/18/99 here is how we tackled this problem package IntMod.Widgets.Listener; import javax.swing.*; import TechMod.Root.ClassworksRoot; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; public class StandardTextFieldFocusListener extends FocusAdapter { protected JTextField textField; protected char filterCharacter; protected StandardFocusAdapter adapter = null; /** @roseuid 37379F320393 */ public StandardTextFieldFocusListener(JTextField tf) { this(tf, null); if (ClassworksRoot.INVARIANT) { assertInvariantImpl(); } if (ClassworksRoot.POSTCOND) { ClassworksRoot.ensure( this, this.textField == tf ); ClassworksRoot.ensure( this, this.adapter == null ); } } /** @roseuid 37379F52023A */ public StandardTextFieldFocusListener(JTextField tf, StandardFocusAdapter a) { textField = tf; adapter = a; if (ClassworksRoot.INVARIANT) { assertInvariantImpl(); } if (ClassworksRoot.POSTCOND) { ClassworksRoot.ensure( this, this.textField == tf ); ClassworksRoot.ensure( this, this.adapter == a ); } } /** @roseuid 37379F830050 */ protected void assertInvariantImpl() { if (ClassworksRoot.INVARIANT) { ClassworksRoot.invariant( this, textField != null ); } } /** @roseuid 37379FA8039D */ public void setFilterCharacter(char f) { this.filterCharacter = f; if (ClassworksRoot.INVARIANT) { assertInvariantImpl(); } if (ClassworksRoot.POSTCOND) { ClassworksRoot.ensure( this, this.filterCharacter == f ); } } /** @roseuid 37379FC602C3 */ public void focusGained(FocusEvent e) { if (adapter != null) { if(textField.isEnabled()) { textField.setBackground(adapter.getFocusGainedColor()); } else { FocusManager.getCurrentManager().focusNextComponent(textField); } }//if else { if(textField.isEnabled()) { textField.setBackground(UIManager.getColor("abc.default.color.focus.gained")); } else { FocusManager.getCurrentManager().focusNextComponent(textField); } }//else textField.repaint(); textField.setCaretPosition(textField.getText().length()); } /** @roseuid 37379FE3008A */ public void focusLost(FocusEvent e) { if (adapter != null) {//if if(textField.isEnabled()) { textField.setBackground(adapter.getFocusLostColor()); } else { textField.setBackground(UIManager.getColor("abc.default.color.hold") ); } }//if else {//else if(textField.isEnabled()) { textField.setBackground(UIManager.getColor("abc.default.color.focus.lost")); } else { textField.setBackground(UIManager.getColor("abc.default.color.hold") ); } } //else if (filterCharacter != '\u0000') { /* Filter out unnecessary separator character (if any). */ if (textField.getText().length() > 0 && textField.getText().charAt(textField.getText().length()-1) == filterCharacter) { try { textField.getDocument().remove(textField.getText().length()-1, 1); } catch(Exception ex) { } } } textField.repaint(); } } (Review ID: 84505) ======================================================================
11-06-2004

EVALUATION Fixed by merlin focus enhancements. hania.gajewska@Eng 2001-04-17
17-04-2001