By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,798 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,798 IT Pros & Developers. It's quick & easy.

Painting on a JPanel - HELP!

P: n/a
I have overridden the following method with:

protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
JigsawPiece tmp;

while (hasNext())
{
tmp = nextJigsawPiece();
g2.drawImage(tmp.getPartialImage(), tmp.getRelativeXCoord(),
tmp.getRelativeYCoord(), this);
}
}

When I load my program, nothing appears. I go to resize the window and the
image appears, I move or resize the window again and it dissappears.

Pleeease help me,
Graham.
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
SPG
Does it help to put this code in the paint() method instead?
I have had trouble with re-painting using swing before, and found that
putting it all inpaint() helped.

Steve
"Graham Norman" <gc**@aber.ac.uk> wrote in message
news:bo**********@titan.btinternet.com...
I have overridden the following method with:

protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
JigsawPiece tmp;

while (hasNext())
{
tmp = nextJigsawPiece();
g2.drawImage(tmp.getPartialImage(), tmp.getRelativeXCoord(),
tmp.getRelativeYCoord(), this);
}
}

When I load my program, nothing appears. I go to resize the window and the
image appears, I move or resize the window again and it dissappears.

Pleeease help me,
Graham.

Jul 17 '05 #2

P: n/a
Graham Norman wrote:
I have overridden the following method with:

protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
JigsawPiece tmp;

while (hasNext())
{
tmp = nextJigsawPiece();
g2.drawImage(tmp.getPartialImage(), tmp.getRelativeXCoord(),
tmp.getRelativeYCoord(), this);
}
}

When I load my program, nothing appears. I go to resize the window and the
image appears, I move or resize the window again and it dissappears.

Pleeease help me,
Graham.

You need to override getPreferredSize() to return the preferred size of
the JPanel.

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.