I have JInternalFrame
contains JTable
. How can I refresh JInternalFrame
Or JTable
when click JButton ---> update
.
Asked
Active
Viewed 2,033 times
0

trashgod
- 203,806
- 29
- 246
- 1,045

user1625324
- 93
- 1
- 1
- 7
-
1Please edit your question to include an [sscce](http://sscce.org/) that exhibits the problem you describe. – trashgod Sep 23 '12 at 13:04
-
http://stackoverflow.com/questions/10516213/jtable-refresh-are-not-displayed – Alvin Pradeep Sep 23 '12 at 16:20
-
Maybe create a `TableModel` and use `fireTableStructureChanged()` – giannis christofakis Sep 23 '12 at 23:49
2 Answers
0
The simplest way is to call .repaint()
in the actionlistener. For example:
public class RefreshingButton extends JButton implements ActionListener{
private static final long serialVersionUID = 1L;
private final JComponent componentToRefsesh;
public RefreshingButton(JComponent toRefresh) {
super("Refresh JTable");
this.componentToRefsesh = toRefresh;
this.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
componentToRefsesh.repaint();
}
}
The best way is to use the Model-View-Controller design pattern. http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

Pieter
- 777
- 5
- 17
-
AFAIK repaint are for Graphics(2D), notify LayoutManager after changes into Components Tree, the same in this for doLayout or notify – mKorbel Sep 23 '12 at 14:07
-
1no. a) don't subclass a JSomething, instead use it b) don't expose api that's not meant for public usage (here's that the actionListener callback), instead instantiate/implement the listener internally and use it c) most of the time a repaint appears to be needed, somthing is wrong with the setup – kleopatra Sep 23 '12 at 16:00