Reputation: 312
I've JTabbedPane tb and I've added 5 JPanels in it as illustrated in below code. Those 5 Panels are separate Java Classes put in same package. Each of these Classes have function named refreshTable(). How can I call that function whenever I switch to corresponding tab?
JTabbedPane tb=new JTabbedPane();
tb.add("विक्री",new ReportPanel());
tb.add("बिल",new BillPanel());
tb.add("ग्राहक",new CustomerPanel());
tb.add("वर्तमानपत्र/मासिक",new ProductPanel());
tb.add("सेटींग्स",new Settings());
tb.addChangeListener((ChangeEvent e) -> {
// Here I want to call function refreshTable() from switched JPanel Class.
});
Upvotes: 0
Views: 92
Reputation: 324128
How can I call that function whenever I switch to corresponding tab?
You can add a ChangeListener
to the JTabbedPane.
An event will be generated every time a new tab is selected. You can then get the panel on the current tab and invoke the refreshTable()
method for that panel.
You can read the section from the Swing tutorial on How to Write a ChangeListener for a simple example of how the listener works.
Upvotes: 1