-
Bug
-
Resolution: Fixed
-
P3
-
6u12, 6u16, 7
-
b134
-
generic, x86
-
generic, windows_xp
-
Not verified
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.
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.
- duplicates
-
JDK-6778882 InternalFrame within glass pane goes below a heavy weight component
- Closed
-
JDK-6921668 Mixing of heavy and lightweight components not working in specific instances
- Closed
- relates to
-
JDK-7023013 Hw/Lw painting artifacts
- Closed
-
JDK-6871485 Performance optimization of the HW/LW Mixing
- Closed