changin a jpanel's content in an applcation

Hi , i have a jpanel which i need to update dynamicly and i can't seem to make it work it won't change sometimes am i doing it right ?

ImageIcon default_image =new ImageIcon(path+"default.png");

JLabel jlabel_default_image =new JLabel(default_image);

jlabel_default_image.setBounds(0, 0, default_image.getIconWidth(), default_image.getIconHeight());

c.weightx = 0.0;

c.gridwidth = 7;

c.gridx = 0;

c.gridy = 1;

add(jlabel_default_image,c);

...

if ((!jcombobox_one_error)&&(!jcombobox_two_error)&&(!jcombobox_three_error))

{

System.out.println("creating new chart");

todayfilename = path+jcombobox_four.getSelectedItem()+END_FILE;

yesterdayfilename = path+jcombobox_five.getSelectedItem()+END_FILE;

LoadData();

final JFreeChart chart = createChart(dataset);

final ChartPanel chartPanel =new ChartPanel(chart);

chartPanel.setPreferredSize(new Dimension(1000, 500));

jpanel = chartPanel;

jpanel.setBounds(0,0,chartPanel.getWidth(),chartPanel.getHeight());

add(jpanel,c);

}

[1461 byte] By [Kernel_77a] at [2007-11-26 22:43:08]
# 1
Once a container has been displayed, you have to validate it after you remove and/or add components to it. Check out the API for Container.add(Component comp, Object constraints).
smalinowa at 2007-7-10 11:59:13 > top of Java-index,Desktop,Core GUI APIs...
# 2
After you add() or remove() you need to validate() and repaint().
itchyscratchya at 2007-7-10 11:59:13 > top of Java-index,Desktop,Core GUI APIs...
# 3
it's an application how can i repaint() ? and i forgot to mention the application does it many times i want to change the jpanel sevral times .
Kernel_77a at 2007-7-10 11:59:13 > top of Java-index,Desktop,Core GUI APIs...
# 4

it's an application how can i repaint() ?

Call repaint(). You call it on the container which you have modified via add() or remove().

and i forgot to mention the application does it many times i want to change the jpanel sevral times .

The call update() and repaint() many times, or if you call it many times in a single branch of the call stack, just call validate() and repaint() at the end.

itchyscratchya at 2007-7-10 11:59:13 > top of Java-index,Desktop,Core GUI APIs...
# 5

Ok thanks it's a extends JPanel class (inside a main jtabbedpane application)

so i did a add(chart) this.validate() and then this.repaint() .

but i get the impression it does not realy delete the original value of the jpanel because sometimes when i load i can see white square (the default.png) and then i click on the jpanel and everything is OK ....

Kernel_77a at 2007-7-10 11:59:13 > top of Java-index,Desktop,Core GUI APIs...
# 6
If you already have a component in a container which you no longer want then you should remove it using one of the remove(xxx) methods, or use the removeAll() method if you want to get rid of all components in the container. Remove what you don't want, add what you do want, call
smalinowa at 2007-7-10 11:59:13 > top of Java-index,Desktop,Core GUI APIs...
# 7
thank you everybody who replied it's working great now .
Kernel_77a at 2007-7-10 11:59:13 > top of Java-index,Desktop,Core GUI APIs...