How to update a pane on a JTabbedPane when another has changed
Hi guys,
I'mhoping that someone has an easy answer for me.....
Basically,
I have a JTabbedPane wih 4 panels, which are all display when the application is opned. 2 of which allow a user to edit information but one of the others needs to visually display the updated information when it is clicked, does anyone know of any way to update the contents of the pane when the user click on that particular pane? Or any other suggestions aroun dthis one.....?
Thanks a lot
Sarah
[509 byte] By [
sasquata] at [2007-11-26 12:40:20]

# 4
I have tried using a ChangeListener to listen for the tab beng pressed....this works but when this tab is pressed I would like that panel to be completely refreshed, i.e. start from scratch drawing it again so that it obtains the most updated list from a file, becuase some of the other tab allow the user to add and delete information from this file.
tabbedPane.addChangeListener(new ChangeListener() {
// This method is called whenever the selected tab changes
public void stateChanged(ChangeEvent evt) {
JTabbedPane pane = (JTabbedPane)evt.getSource();
// Get current tab
if(pane.getSelectedIndex()==1)
{
System.out.println("the view tab has been chosen......");
pane.updateUI();
}
}
});
I have tried using pane.updateUI(), which causesthe following errors:-
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTabbedPaneUI.scrollableTabLayoutEnabled(BasicTabbedPaneUI.java:240)
at javax.swing.plaf.basic.BasicTabbedPaneUI.access$300(BasicTabbedPaneUI.java:37)
at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.stateChanged(BasicTabbedPaneUI.java:3200)
at javax.swing.JTabbedPane.fireStateChanged(JTabbedPane.java:290)
at javax.swing.JTabbedPane$ModelListener.stateChanged(JTabbedPane.java:222)
at javax.swing.DefaultSingleSelectionModel.fireStateChanged(DefaultSingleSelectionModel.java:116)
at javax.swing.DefaultSingleSelectionModel.setSelectedIndex(DefaultSingleSelectionModel.java:50)
at javax.swing.JTabbedPane.setSelectedIndexImpl(JTabbedPane.java:478)
at javax.swing.JTabbedPane.setSelectedIndex(JTabbedPane.java:464)
at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.mousePressed(BasicTabbedPaneUI.java:3237)
at java.awt.Component.processMouseEvent(Component.java:5485)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3889)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
I have also tried pane.revalidate() and pane.repaint() but these did not seem to make any changes at all to the tad displayed...