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

Mixing of heavy and lightweight components not working in specific instances

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 6u16
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      C:\Documents and Settings\kyle.smith>java -version
      java version "1.6.0_16"
      Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
      Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP SP3

      A DESCRIPTION OF THE PROBLEM :
      Heavyweight components paint on top of light weight components if the heavy weight components are in JInternalPanes inside a JDesktopPane that has GridBagLayout or is inside a JScrollPane.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a JDesktopPane with several JInternalFrames inside it.
      Add a heavy weight button to each internal frame.

      Incorrect painting happens when:
      1. The layout on the JDesktopPane is set to GridBagLayout (didn't try other layouts) - the button paints on top of adjacent components when dragging the internal frame

      2. The JDesktopPane is in a JScrollPane - the button paints on top of adjacent components when scrolling but not when dragging the internal frame.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expect heavy weight buttons to clip appropriately when moving and scrolling.
      Internal frames behave appropriately.
      ACTUAL -
      Buttons show on top of components outside the JDesktopPane and on top of other internal panes when they should not.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
          private void createAndShowGUI() {
              //Create and set up the window.
              frame = new JFrame("HelloWorldSwing");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setPreferredSize(new Dimension(200, 200));

              JPanel panel = new JPanel();
              panel.setLayout(new GridBagLayout());
              frame.getContentPane().add(panel);
              
              JButton testButton = new JButton("This is a test");
              testButton.setBackground(Color.CYAN);
              testButton.setOpaque(true);
              GridBagConstraints gbc = new GridBagConstraints();
              gbc.gridx = 0;
              gbc.gridy = 0;
              gbc.fill = GridBagConstraints.HORIZONTAL;
              gbc.gridwidth = GridBagConstraints.REMAINDER;
              panel.add(testButton, gbc);
              
              JPanel lwPanel = new JPanel(new GridBagLayout());
              Dimension dimension = new Dimension(500, 500);
              lwPanel.setPreferredSize(dimension);
              lwPanel.setMinimumSize(dimension);
              
              JScrollPane scroller = new JScrollPane(lwPanel);
              scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
              gbc = new GridBagConstraints();
              gbc.gridx = 0;
              gbc.gridy = 1;
              gbc.weightx = 1;
              gbc.weighty = 1;
              gbc.fill = GridBagConstraints.BOTH;
              gbc.gridwidth = GridBagConstraints.REMAINDER;
              panel.add(scroller, gbc);
            
              
              JDesktopPane desktop = new JDesktopPane();
      // desktop.setLayout(new GridBagLayout());
              gbc = new GridBagConstraints();
              gbc.weightx = 1;
              gbc.weighty = 1;
              gbc.fill = GridBagConstraints.BOTH;
              lwPanel.add(desktop, gbc);

              String[] titles = {"one", "two", "three", "four", "five"};
              for (int i=0; i<5; i++)
              {
      JInternalFrame iFrame = new JInternalFrame(titles[i], true, true, true, true);
      iFrame.setLayout(new GridBagLayout());
      iFrame.setPreferredSize(new Dimension(150, 55));
      iFrame.setLocation(20, i*60);
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = i;
      desktop.add(iFrame);

      Button button = new Button("HW Button");
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 1;
      iFrame.add(button, gbc);

      iFrame.pack();
      iFrame.setVisible(true);
              }
              
              testButton = new JButton("This is a test");
              testButton.setBackground(Color.CYAN);
              testButton.setOpaque(true);
              gbc = new GridBagConstraints();
              gbc.gridx = 0;
              gbc.gridy = 2;
              gbc.fill = GridBagConstraints.HORIZONTAL;
              gbc.gridwidth = GridBagConstraints.REMAINDER;
              panel.add(testButton, gbc);

              frame.pack();
              frame.setVisible(true);
          }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Partial workaround is to put the scroll pane in a heavy weight panel.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              alexp Alexander Potochkin (Inactive)
              Reporter:
              igor Igor Nekrestyanov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: