JDK-4259934 : Set contentPane to transparent will generate graphics paint problem.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_7
  • CPU: sparc
  • Submitted: 1999-08-05
  • Updated: 2000-08-05
  • Resolved: 2000-08-05
Related Reports
Duplicate :  
Description
JDK: 1.2, 1.3
OS: Solaris, Windows
Locale: All

According to JDK1.2's api specification, programmer can set JFrame's contentPane
to transparent, using setOpaque(false). Then there will exists graphics painting
problem. That is, if in eventDispatch thread, we change the location of one 
JComponent of the contentPane, the contentPane does not clear its previous 
invalid region that the JComponent occupied, but if the contentPane is opaque, 
it will use fillRect(getBackground()) to fill the previous invalid region.

See attached program to show this problem.

Run the attached program, press the button and see what will happen.


jim.hu@prc 1999-08-05

Comments
EVALUATION Yes, this is ultimately because Swing's toplevel components: JFrame, JWindow, JDialog, JApplet do not participate in Swing's Repaint mechanics. If they did, then in this case these components would properly clear their backgrounds on a repaint to the non-opaque content pane would start painting from a clean surface. amy.fowler@Eng 2000-08-04
04-08-2000

SUGGESTED FIX I introduce a fix here, but I am not sure whether it is a good solution. Modified javax.swing.plaf.ComponentUI.java file: from : 38 public void update(Graphics g, JComponent c) { 39 if (c.isOpaque()) { 40 g.setColor(c.getBackground()); 41 g.fillRect(0, 0, c.getWidth(),c.getHeight()); 42 } 43 paint(g, c); 44 } to 38 public void update(Graphics g, JComponent c) { 39 if (c.isOpaque()) { 40 g.setColor(c.getBackground()); 41 g.fillRect(0, 0, c.getWidth(),c.getHeight()); 42 } else { 43 g.clearRect(0, 0, c.getWidth(),c.getHeight()); 44 } 45 paint(g, c); 46 } jim.hu@prc 1999-08-05
05-08-1999