JDK-6826074 : JScrollPane does not revalidate the component hierarchy after scrolling
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u12,6u16,7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2009-04-03
  • Updated: 2012-10-01
  • Resolved: 2011-05-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b134Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
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.

Comments
EVALUATION we should respect validating rule
27-09-2010

WORK AROUND The workaround for 6778882 should help resolve this issue.
05-05-2009