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?
How to reload a JPanel?
Asked Answered
please whats is reload, for better help sooner post an SSCCE, short, runnable, compilable –
Tacitus
What do you mean by "reload" and "refresh" exactly? Show some code, explain with an example what you want to do. –
Shortcircuit
refresh/reload/update all the components in the panel... some of the components are displaying info that is being updated through jdbc –
Yogh
you should just use the Graphics instance of the JPanel. –
Hydroplane
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. –
Shortcircuit
@Manish Doshi s/he want to setText based on value from JDBC, then Graphics haven't something with –
Tacitus
@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, hopefully this might be of some help. –
Pizarro
This works fine for me. But after an other
_panel.revalidate();
_panel.repaint();
first removeAll() to remove all components _panel.removeAll(); _panel.revalidate(); _panel.repaint(); –
Vinosity
You could also refresh the entire JFrame
to update every component, and not just the panel and its components:
this.revalidate();
this
being the instance of your JFrame
, if your class extends JFrame, just use this
.
© 2022 - 2024 — McMap. All rights reserved.