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

Inconsistent opacity behaviour between JCheckBox and JRadioButton

    XMLWordPrintable

Details

    • b22
    • x86
    • windows_7

    Backports

      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 ----------

        Attachments

          Issue Links

            Activity

              People

                alexsch Alexandr Scherbatiy
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: