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

JScrollPane does not revalidate the component hierarchy after scrolling

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b134
    • CPU:
      generic, x86
    • OS:
      generic, windows_xp
    • Verification:
      Not verified

      Description

      The HW/LW Mixing feature relies upon validity of the component hierarchy (see Component.isValid()/invalidate()/validate(), and JComponent.revalidate()). This is to avoid recalculating shapes for components in invalid containers because mostly these shapes would be incorrectly calculated (due to temporary container's layout invalidity).

      This means that an application using the HW/LW Mixing feature must keep its component hierarchy valid: it must call the validate()/revalidate() methods appropriately after performing actions that invalidate the component hierarchy (like setBounds() and some other). However, some operations get performed by the GUI toolkit itself, and the user may be unaware of these actions. Which makes the GUI toolkit responsible for validation of the components.

      Consider the following example:

      import java.awt.BorderLayout;
      import java.awt.Button;
      import java.awt.Dimension;
      import java.awt.FlowLayout;

      import javax.swing.BorderFactory;
      import javax.swing.JComponent;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JScrollPane;

      public class HLMixTest {
          public static void main(String[] args)
          {
              JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
              p.add(new Button("Test"));
              p.setPreferredSize(new Dimension(500, 500));
              JScrollPane sp = new JScrollPane(p);

              JFrame f = new JFrame();
              f.getContentPane().add(sp, BorderLayout.CENTER);
              ((JComponent) f.getContentPane()).setBorder(
              BorderFactory.createEmptyBorder(50, 50, 50, 50));
              f.setSize(400, 400);
              f.setLocationRelativeTo(null);
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              f.setVisible(true);
          }
      }

      It adds a HW button into a LW ScrollPane. Scrolling the ScrollPane does move the button, however does not recalculate its shape correctly. This is beacuse the ScrollPane does not revalidate the component hierarchy upon scrolling (hit Ctrl-Shift-F1 before scrolloing and after that to get the component hierarchy printed in the console and see how the component tree becames marked invalid). The only way to get the correct shape back is to resize the whole frame.

      THe ScrollPane must revalidate the component hierarchy after each scrolling action in order for the HW/LW mixing feature to work correctly.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              alexp Alexander Potochkin (Inactive)
              Reporter:
              anthony Anthony Petrov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: