This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JDK 5.0 RC Repaint Bug Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JDK 5.0 RC Repaint Bug" Watch "JDK 5.0 RC Repaint Bug" New topic

JDK 5.0 RC Repaint Bug

Joseph Goodman

Joined: Aug 31, 2004
Posts: 18
I have been playing around with JDK 5.0 RC and I have noticed a reapaint bug. The following code on my machine, using JDK 5.0 RC will sometimes not repaint the JFrame after resizing it. Am I just doing something crazy or is this a serious bug? I never had this problem with JDK 1.4.1.

Thanks in advance

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

public class AlphaTest extends JFrame
private Color mTransparentColor = new Color(0, 1, 2, 0);
/** Create the alpha test. */
public AlphaTest()
setSize(800, 600);
setTitle("Alpha Test");

addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)

public final void paint(Graphics g)
Graphics2D G2d = (Graphics2D)g;

BufferedImage BackBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D BackBufferGraphics = BackBuffer.createGraphics();

BackBufferGraphics.fillRect(0, 0, getWidth(), getHeight());

BackBufferGraphics.fillRect(20, 20, 100, 100);

G2d.fillRect(0, 0, getWidth(), getHeight());

G2d.drawImage(BackBuffer, 0, 0, this);

/** The main loop of the program .*/
public static void main(String args[])
new AlphaTest().setVisible(true);
Bernhard Jung

Joined: Sep 14, 2004
Posts: 11
Custom painting should be done in a different way.
Read this:

Create a class that inherits from JPanel, override the paintComponent method and add an instance of it to a JFrame.

import javax.swing.*;
import java.awt.*;

public class PaintTest extends JPanel

public PaintTest()

public final void paintComponent(Graphics g)

g.fillRect(20, 20, 100, 100);

public static void main(String args[])
JFrame frame = new JFrame("PaintTest");
frame.setSize(800, 600);
frame.add(new PaintTest());
I agree. Here's the link:
subject: JDK 5.0 RC Repaint Bug
It's not a secret anymore!