8

I'm a java newbie... I need to know how to reload a JPanel? I extended the JPanel class and created a panel that will run in a cardlayout in an Applet. I want this panel to reload/refresh after the user clicks a button in this panel. I tried including the revalidate() and repaint() methods (methods I don't understand well) in the ActionListener for the button but nothing happened. Can anyone throw some light on how to correctly refresh the whole panel?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
JLA
  • 329
  • 1
  • 6
  • 12
  • 3
    please whats is reload, for better help sooner post an [SSCCE](http://sscce.org/), short, runnable, compilable – mKorbel Jul 12 '13 at 06:09
  • 2
    What do you mean by "reload" and "refresh" exactly? Show some code, explain with an example what you want to do. – JB Nizet Jul 12 '13 at 06:09
  • refresh/reload/update all the components in the panel... some of the components are displaying info that is being updated through jdbc – JLA Jul 12 '13 at 06:13
  • you should just use the Graphics instance of the JPanel. – Manish Doshi Jul 12 '13 at 06:22
  • 2
    Let's take a JLabel for example, whose text is reloaded from the database. To make it display the new text, use label.setText(). For a JTable, use table.setModel(), or update the data in its model. For a JTextArea, setText(), etc. – JB Nizet Jul 12 '13 at 06:22
  • 2
    @Manish Doshi s/he want to setText based on value from JDBC, then Graphics haven't something with – mKorbel Jul 12 '13 at 06:23
  • @user2108393 : If you are looking for something like, an event that can clear all the fields and other components of their previous values, you can have a look at this [example](http://stackoverflow.com/a/13378672/1057230), hopefully this might be of some help. – nIcE cOw Jul 12 '13 at 13:39

1 Answers1

20

This works fine for me. But after an other

_panel.revalidate();
_panel.repaint();
M.K.
  • 256
  • 1
  • 6