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

Inconsistent opacity behaviour between JCheckBox and JRadioButton

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7u51
    • Fix Version/s: 9
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b22
    • CPU:
      x86
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.7.0_51"
      Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
      Java HotSpot(TM) 32-Bit Server VM (build 24.51-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      When using the MetalLookAndFeel and the DefaultMetalTheme, a JCheckBox can be set to have a transparent background but the JRadioButton can't.

      I am using setOpaque(false) to set transparency on both the components. When comparing MetalIconFactory.CheckBoxIcon.paintIcon() with MetalIconFactory.RadioButtonIcon.paintIcon() it is clear that only RadioButtonIcon will always fillRect. CheckBoxIcon will not fillRect unless the checkbox is pressed.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See Source Code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Both JRadioButon and JCheckBox should be able to have transparent backgrounds by setting setOpaque(false)
      ACTUAL -
      Only JCheckBox can have a transparent background when the DefaultMetalTheme and MetalLookAndFeel are used.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Compile the following 2 classes and run Main.main()


      public class Main {
          public static MainFrame ex = null;

          public Main() {
          }

          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      try {
                          MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
                          UIManager.setLookAndFeel(new MetalLookAndFeel());
                      } catch (UnsupportedLookAndFeelException e) {
                          e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                      }

                      ex = new MainFrame();
                      ex.setVisible(true);
                  }
              });
          }

      }


      public class MainFrame extends JFrame
      {
          public MainFrame() {
              initUI();
          }

          private void initUI() {
              JPanel panel = new JPanel();
              panel.setBackground(Color.GREEN);
              getContentPane().add(panel);

              panel.setLayout(new FlowLayout());

              JCheckBox cb = new JCheckBox();
              cb.setOpaque(false);
              panel.add(cb);

              JRadioButton rb = new JRadioButton();
              rb.setOpaque(false);
              panel.add(rb);

              setTitle("Checkbox is tranparent but radio button is not");
              setSize(600, 400);
              setLocationRelativeTo(null);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
          }

      }
      ---------- END SOURCE ----------

        Activity

        Hide
        dmarkov Dmitry Markov added a comment -
        The problem is reproducible on jdk8u05.
        Show
        dmarkov Dmitry Markov added a comment - The problem is reproducible on jdk8u05.
        Hide
        hgupdate HG Updates added a comment -
        URL: http://hg.openjdk.java.net/jdk9/client/jdk/rev/a1635cd4bdb5
        User: alexsch
        Date: 2014-05-21 10:14:18 +0000
        Show
        hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/client/jdk/rev/a1635cd4bdb5 User: alexsch Date: 2014-05-21 10:14:18 +0000
        Hide
        hgupdate HG Updates added a comment -
        URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/a1635cd4bdb5
        User: lana
        Date: 2014-07-09 17:53:06 +0000
        Show
        hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/a1635cd4bdb5 User: lana Date: 2014-07-09 17:53:06 +0000

          People

          • Assignee:
            alexsch Alexander Scherbatiy (Inactive)
            Reporter:
            webbuggrp Webbug Group
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: