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

SynthTreeUI ignores opacity

    XMLWordPrintable

Details

    Description

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

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

      A DESCRIPTION OF THE PROBLEM :
      javax.swing.plaf.synth.SynthTreeUI ignores javax.swing.JComponent 'opaque' property. I mean that if you put opaque property to false the background is still painted. In my opinion it should not.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :

      This test case works only on UNIX because it uses Gnome LookAndFeel (extending SynthLookAndFeel) to prove the problem.
      How to run:
      Open the project with NetBeans, run it.
      Click Metal and Gnome buttons to change the current look and feel of the frame.
      Expected behaviour:
      When clicking Metal button, the tree background is red.
      When clicking Gnome button, the tree background should be red because it is the frame background color.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Actual behaviour:
      CORRECT. When clicking Metal button, the tree background is red (as it is the frame background color).
      INCORRECT. When clicking Gnome button, the tree background is white. Furthermore, the tree background color (blue) should be displayed because of ignoring opacity, but it is the default text background color that is displayed.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package test;
      import java.awt.Color;
      import javax.swing.SwingUtilities;
      import javax.swing.UIManager;
      import javax.swing.UnsupportedLookAndFeelException;
      /**
       *
       * @author Laurent Sauvage
       */
      public class TransparentTreeFrame extends javax.swing.JFrame {
         
          /** Creates new form TransparentTreeFrame */
          public TransparentTreeFrame() {
              initComponents();
              jScrollPane1.getViewport().setOpaque(false);
              getContentPane().setBackground(Color.red);
          }
         
          /** This method is called from within the constructor to
           * initialize the form.
           * WARNING: Do NOT modify this code. The content of this method is
           * always regenerated by the Form Editor.
           */
          //
          private void initComponents() {
              jToolBar1 = new javax.swing.JToolBar();
              jButton1 = new javax.swing.JButton();
              jButton2 = new javax.swing.JButton();
              jScrollPane1 = new javax.swing.JScrollPane();
              jTree1 = new javax.swing.JTree();
              setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
              jButton1.setText("Metal");
              jButton1.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(java.awt.event.ActionEvent evt) {
                      jButton1ActionPerformed(evt);
                  }
              });
              jToolBar1.add(jButton1);
              jButton2.setText("Gnome");
              jButton2.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(java.awt.event.ActionEvent evt) {
                      jButton2ActionPerformed(evt);
                  }
              });
              jToolBar1.add(jButton2);
              getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);
              jScrollPane1.setOpaque(false);
              jTree1.setBackground(java.awt.Color.blue);
              jTree1.setOpaque(false);
              jScrollPane1.setViewportView(jTree1);
              getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
              pack();
          }//
          private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
              try {
                  UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
                  SwingUtilities.updateComponentTreeUI(this);
              } catch (ClassNotFoundException ex) {
                  ex.printStackTrace();
              } catch (InstantiationException ex) {
                  ex.printStackTrace();
              } catch (IllegalAccessException ex) {
                  ex.printStackTrace();
              } catch (UnsupportedLookAndFeelException ex) {
                  ex.printStackTrace();
              }
          }
          private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
              try {
                  UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
                  SwingUtilities.updateComponentTreeUI(this);
              } catch (ClassNotFoundException ex) {
                  ex.printStackTrace();
              } catch (InstantiationException ex) {
                  ex.printStackTrace();
              } catch (IllegalAccessException ex) {
                  ex.printStackTrace();
              } catch (UnsupportedLookAndFeelException ex) {
                  ex.printStackTrace();
              }
          }
         
         
          // Variables declaration - do not modify
          private javax.swing.JButton jButton1;
          private javax.swing.JButton jButton2;
          private javax.swing.JScrollPane jScrollPane1;
          private javax.swing.JToolBar jToolBar1;
          private javax.swing.JTree jTree1;
          // End of variables declaration
          /**
           * @param args the command line arguments
           */
          public static void main(String args[]) {
              java.awt.EventQueue.invokeLater(new Runnable() {
                  public void run() {
                      new TransparentTreeFrame().setVisible(true);
                  }
              });
          }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      patch javax.swing.plaf.synth.SynthTreeUI.update(Graphics g, JComponent c)
      with this body:
      SynthContext context = getContext(c);
      SynthLookAndFeel.update(context, g);
      if (c.isOpaque() {
          context.getPainter().paintTreeBackground(context, g, 0, 0, c.getWidth(), c.getHeight());
      }
      paint(context, g);
      context.dispose();

      Attachments

        Activity

          People

            peterz Peter Zhelezniakov
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Imported:
              Indexed: