Note that there are some explanatory texts on larger screens.

plurals
  1. POChange location JLabel on JPanel repaint
    text
    copied!<p>I'm building a Java application. GameView has a BoardView which contains multiple PawnViews (in the example just one).</p> <p>Example:</p> <pre><code> 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); } } </code></pre> <p>Initially everything looks great (without the MovePawn):</p> <p><a href="http://dl.dropbox.com/u/7438271/1.png" rel="nofollow">http://dl.dropbox.com/u/7438271/1.png</a></p> <p>When I call MovePawn it looks like:</p> <p><a href="http://dl.dropbox.com/u/7438271/2.png" rel="nofollow">http://dl.dropbox.com/u/7438271/2.png</a></p> <p>I tried to call <code>this.revalidate()</code>, <code>this.updateUI()</code>, <code>this.repaint()</code>, <code>this.paintImmediately()</code> in various forms but they all make it worse: the whole JPanel gets a white background.</p> <p>I also tried to override the paintComponent function of the JPanel also without effect.</p> <p>This only occurs on Mac OS X (fully updated) but I experience some problems with repainting in Windows as well.</p> <p>Can anyone please help out?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload