JDK-6371910 : Actions regression when changing enabled via putValue("enabled", ...);
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-01-12
  • Updated: 2010-04-02
  • Resolved: 2006-03-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b76Fixed
Related Reports
Relates :  
Description
The following works in 1.5, but not the latest 1.6 builds:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ActionTest {
    public static void main(String[] args) {
        Action action = new FooAction();
        JToolBar toolBar = new JToolBar();
        JButton toolBarButton = toolBar.add(action);
        JButton button = new JButton(action);

        // action.setEnabled(false);
        action.putValue("enabled", Boolean.FALSE);
        if (toolBarButton.isEnabled()) {
            System.out.println("toolbar button should not be enabled");
        }
        if (button.isEnabled()) {
            System.out.println("button should not be enabled");
        }
    }

    private static class FooAction extends AbstractAction {
        public void actionPerformed(ActionEvent e) {
        }
    }
}

Comments
EVALUATION The best way to address this problem is to make putValue("enabled", xxx) equivalent to setEnabled(xxx), and getValue("enabled") equivalent to isEnabled. This way there is no inconsistancy between the two and PropertyChangeListeners, such as JButton, can not get out of sync.
22-02-2006

EVALUATION This is the result of changing the code to always look at the value from the Action instead of the PropertyChangeEvent. This ones a bit tricky in that with the code: getValue("enabled") != isEnabled None-the-less it is a regression and I'll fix it by prefering the value from the change event.
12-01-2006