JPanel+Image

Hi,

I want to display a graph (image) in a Jpanel. How can I dynamically set a new graph as users press startButton.

if(evt.getSource().equals(startButton)){

addImage(jPanel4,img);

getContentPane().add(jPanel4);

jPanel4.setBounds(340, 180, 322, 250);

jPanel4.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); }

For this code: it correclty displays the image, but pressing the startButton twice, e.g. during certain run did not display a new figure (it should do becuase my program gives different results each time the user presses StartButton). However, if I run the program again (by closing and running) it will disply it correctly.

[699 byte] By [MoonSpotLighta] at [2007-11-27 2:29:23]
# 1
sounds like you need to add a call to repaint() somewhere but without code it's hard to say
tjacobs01a at 2007-7-12 2:42:31 > top of Java-index,Desktop,Core GUI APIs...
# 2
Add a label to the panel. Add the image to the label. Whenever you want to change the image you just use:label.setIcon( new ImageIcon(....) );
camickra at 2007-7-12 2:42:31 > top of Java-index,Desktop,Core GUI APIs...