I'm building a Java application. GameView has a BoardView which contains multiple PawnViews (in the example just one).
Example:
public class GameView extends Frame
{
public GameView()
{
AWTUtilities.setWindowOpaque(this, false);
this.setUndecorated(true);
this.setLayout(null);
this.setResizable(false);
this._boardview = new BoardView();
int x = 0;
int y = 0;
PawnView pv = new PawnView();
this._boardview.AddPawn(pv, 10, 10);
this._boardview.MovePawn(pv, 20, 10);
}
}
public class BoardView extends JPanel
{
public BoardView()
{
this.setOpaque(false);
RepaintManager.currentManager(null).setDoubleBufferingEnabled(true);
this.setLayout(null);
}
@Override
public void update(Graphics g)
{
paint(g);
}
public void AddPawn(PawnView pawnview, int x, int y)
{
this.add(pawnview);
pawnview.setLocation(x, y);
}
public void MovePawn(PawnView pawnview, int x, int y)
{
pawnview.setLocation(x, y);
//this.repaint();
}
}
public class PawnView extends JLabel
{
public PawnView()
{
this.setOpaque(false);
RepaintManager.currentManager(null).setDoubleBufferingEnabled(true);
this.setLayout(null);
}
}
Initially everything looks great (without the MovePawn):
http://dl.dropbox.com/u/7438271/1.png
When I call MovePawn it looks like:
http://dl.dropbox.com/u/7438271/2.png
I tried to call this.revalidate()
, this.updateUI()
, this.repaint()
, this.paintImmediately()
in various forms but they all make it worse: the whole JPanel gets a white background.
I also tried to override the paintComponent function of the JPanel also without effect.
This only occurs on Mac OS X (fully updated) but I experience some problems with repainting in Windows as well.
Can anyone please help out?