473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Painting on a JPanel - HELP!

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
2 3903
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Moth | last post by:
I have a PlotPanel class that extends JPanel which I have used previously to display charts in swing guis. I now want to display a graph in a jsp page so I was going to generate the graph and then...
7
by: Seanus | last post by:
Hey all, I've recently started coding a program for my final year project of my uni degree. I am coding in Swing and have a very odd bug. I'm using TabbedPane for the first time, although I've...
6
by: davedwm | last post by:
I'm trying to display a grid of TextPane's that are sized to fit a JPanel i've drawn into a Dialog class, the number of 'Cells' are entered into JTextFields and when the appropriate button is hit...
1
by: dishal | last post by:
Hi, Im having a problem with typing on the JPanel. The thing is, that it works perfectly fine when this line " content.add(jp, BorderLayout.NORTH); " is taken out (its the buttons panel) but when its...
1
by: tommyny04 | last post by:
I have a method addPlayer that's supposed to add a JLabel to a JPanel and update the JPanel. The JLabel is just a label with a player's name in it. The code I've wrote doesn't work and I'm not sure...
1
by: Kid Programmer | last post by:
Hello guys. I was wondering if it is possible to perform custom painting in a GUI window using C++. In Java you can do this by using the following code:import javax.swing.SwingUtilities; import...
8
by: eddiewould | last post by:
Hi, I want to write a custom widget which will act similarly to a JPanel (i.e it can contain other Components), but semantically it's not a kind of JPanel so it shouldn't extend from it. Here is...
1
by: Akino877 | last post by:
Hello, I have a question regarding Java and Swing programming I wonder if I could ask the forum for some help. I have a JPanel that has a couple of radio buttons and an "OK/Next" button on it. ...
2
mrjohn
by: mrjohn | last post by:
Hey, I've got some code that is supposed to paint part of an image on a JPanel. Unfortunately, when I run it, I get a nullPointer Exception. public void paintMap() { Graphics g =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.