JPanel: both implementing my own paintComponent() and rendering children doesn't work
Posted
by Paul Marshall
on Stack Overflow
See other posts from Stack Overflow
or by Paul Marshall
Published on 2010-05-02T06:00:09Z
Indexed on
2010/05/02
6:07 UTC
Read the original article
Hit count: 310
I'm extending a JPanel to display a game board, and adding a JEditorPane at the bottom to hold some status text. Unfortunately, the game board renders just fine, but the JEditorPane is just a blank gray area until I highlight the text in it, when it will render whatever text is highlighted (but not the rest). If I'm understanding Swing right, it should work, because super.paintComponent(g) should render the other children (i.e., the JEditorPane). Tell me, o great stackoverflow, what bonehead mistake am I making?
public GameMap extends JPanel {
public GameMap() {
JEditorPane statusLines = new JEditorPane("text/plain","Stuff");
this.setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS));
this.add(new Box.Filler(/*enough room to draw my game board*/));
this.add(statusLines);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
for ( all rows ){
for (all columns){
//paint one tile
}
}
}
}
© Stack Overflow or respective owner