aspose file tools*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JDK 5.0 RC Repaint Bug" Watch "JDK 5.0 RC Repaint Bug" New topic
Author

JDK 5.0 RC Repaint Bug

Joseph Goodman
Greenhorn

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)
{
System.exit(0);
}
});
}

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.setColor(mTransparentColor);
BackBufferGraphics.fillRect(0, 0, getWidth(), getHeight());

BackBufferGraphics.setColor(Color.red);
BackBufferGraphics.fillRect(20, 20, 100, 100);


G2d.setColor(Color.blue);
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
Greenhorn

Joined: Sep 14, 2004
Posts: 11
Custom painting should be done in a different way.
Read this:
http://java.sun.com/docs/books/tutorial/uiswing/14painting/index.html

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()
{
setBackground(Color.BLUE);
}

public final void paintComponent(Graphics g)
{
super.paintComponent(g);

g.setColor(Color.RED);
g.fillRect(20, 20, 100, 100);
}

public static void main(String args[])
{
JFrame frame = new JFrame("PaintTest");
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new PaintTest());
frame.setVisible(true);
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDK 5.0 RC Repaint Bug