Results 1 to 2 of 2
  1. #1
    javaexplorer is offline Member
    Join Date
    Jan 2010
    Posts
    20
    Rep Power
    0

    Default Diabled JButton won't leave the focus

    Hi,

    The Swing focus sub-systems seems defective to me as it will transfer the focus to a disabled JButton, which is in the focus cycle , but then won't transfer the focus to the next component in the focus cycle on pressing the focus traversal keys.

    Ideally, a diabled components should not receive the focus in the first place.

    I tried to get around it by writing a propertychange listener so that I can set the focusability of any component in the container to false when it is disabled. However, this code does not seem to be working. What is the remedy? What property name to use in this context?

    Java Code:
    class CustomPropertyListener implements PropertyChangeListener {
    
               public void propertyChange(PropertyChangeEvent e) {
                 Component component = (Component) e.getSource();
                 component.setFocusable(component.isEnabled());
                }
           } // end of inner class definition
    
    CustomPropertyListener propertyListener = new CustomPropertyListener();
    
           Component[] components = this.getComponents();
           for(Component component : components) {
               component.addPropertyChangeListener("enabled", propertyListener);
           }

    Regards,
    Dinesh

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    802
    Rep Power
    6

    Default

    I have written a sample code and its work fine.Please post the code with code format.
    Ramya:cool:

Similar Threads

  1. Leave management System
    By anji4u_19 in forum Suggestions & Feedback
    Replies: 24
    Last Post: 04-05-2010, 06:03 PM
  2. NumberFormat which leave fractions as they are
    By itaipee in forum AWT / Swing
    Replies: 2
    Last Post: 12-09-2009, 06:11 PM
  3. problem in doing leave management
    By satkk in forum JDBC
    Replies: 3
    Last Post: 08-19-2009, 05:51 PM
  4. problem in doing leave management
    By satkk in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 04-01-2009, 04:50 PM
  5. Creating a JButton that does not show focus
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-26-2008, 07:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •