Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6546308

JToggleButton background color ignored when selected

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Running on a Dell Latitude D620. Standalone or Network doesn't make a difference

      A DESCRIPTION OF THE PROBLEM :
      Implementing JToggleButton. When toggle button is pressed, the background color setting is ignored. Currently, it only appears to be respected when the button is in the up (non-selected) position. I have attempted to override EVERY option in the UIManager UIDefaults which pertains to "ToggleButton" color properties to override this behavior without success. I have noticed that this has supposedly been a problem since after JDK1.2 and that bugs of a similar nature have been closed and indicated as fixed.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Simply extending JToggleButton and placing within a JFrame. Set the background color to a desired color. Press toggle button. Color is ignored when selected. Depress toggle button (deselected), color setting is respected.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      In this case, the background should always be yellow whether the button is pressed or not. Not my main goal, but I did this approach simply to show that the color is ignored when the button is selected.
      ACTUAL -
      unknown default background color shown when button selected.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class TestToggleButton
      {
        public TestToggleButton()
        {
          JToggleButton appToggleButton = new JToggleButton();
          appToggleButton.addActionListener(new ActionListener()
              {
                public void actionPerformed(ActionEvent e)
                {
                  ((JToggleButton)e.getSource()).setText(((JToggleButton)e.getSource()).isSelected() ? "Selected" : "Not Selected");
                }
              });
          
          appToggleButton.setBackground(Color.YELLOW);
          appToggleButton.setText("Ready to Use");

          JFrame appFrame = new JFrame();
          Container pane = appFrame.getContentPane();
          pane.setLayout(new FlowLayout());
          pane.add(appToggleButton);
          appFrame.pack();
          appFrame.setVisible(true);
        }

        public static void main(String[] args)
        {
          new TestToggleButton() ;
        }
      }
      ---------- END SOURCE ----------

            rupashka Pavel Porvatov (Inactive)
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: