JDK-4939857 : Unnecessary painting in Swing during startup and window resizing
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1,1.4.2,5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux,linux_redhat_9.0
  • CPU: x86
  • Submitted: 2003-10-17
  • Updated: 2003-11-03
  • Resolved: 2003-11-03
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.
Other
5.0 b28Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
Run the following test case and notice that when the app is brought up
the panel is painted twice.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.plaf.basic.*;

public class Test {
    public static void main(String[] args) throws Throwable {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                show();
            }
        });
    }

    private static void show() {
        JFrame frame = new JFrame("TEST");
        JComponent button = new JPanel() {
            public void paint(Graphics g) {
                super.paint(g);
                System.out.println("----------PAINTING---------------------");
                System.out.println("widget bounds: " + getBounds());
                System.out.println("clip: " + g.getClip());
            }
        };
        frame.setLayout(new FlowLayout());
        frame.add(button);
        frame.pack();
        frame.show();
    }
}

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-beta FIXED IN: tiger-beta INTEGRATED IN: tiger-b28 tiger-beta
14-06-2004

EVALUATION There are a couple of problems contributing to this. 1. The child of the JFrame (JRootPane) is not opaque. This is problematic because JComponent.paintImmediately will loop until it finds a !opaque JComponent. If it gets to a Component that isn't a JComponent it'll invoke repaint on it. This lead to excessive repaints on the Frame. This is fixed by invoke setOpaque(true) on the JRootPane created for the top levels (JFrame/JWindow/JDialog/JApplet). 2. When a top level's size changes the JRootPane gets resized too, leading to a pending repaint (from the AWT side) for the top level, and a pending Swing repaint for the JRootPane. This can be fixed by making the RepaintManager know that it is about to paint a RootPane and if necessary cancel any pending AWT paint events that would generate the same thing. 3. While not directly related JComponent's reshape method now overlaps with that of Component.reshape. JComponent's reshape is no longer needed so that it now invokes super.reshape. ###@###.### 2003-10-20
20-10-2003