0

I have JInternalFrame contains JTable. How can I refresh JInternalFrame Or JTable when click JButton ---> update.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
user1625324
  • 93
  • 1
  • 1
  • 7

2 Answers2

2

When you update your TableModel, the JTable should refresh itself automatically. If not, your TableModel should be corrected, for example.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
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
  • 1
    no. 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