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]
# 1

> but one of the others needs to visually display the updated information

Your question is so vague that we can't really give an answer, but generally:

1) Update the information when it is entered on the other text pane.

or

2) Use a changeListener to be notified of a tab change

camickra at 2007-7-7 16:11:40 > top of Java-index,Desktop,Core GUI APIs...
# 2

Basically, one of the tabbed panes (visual tab) collects information from a file. 2 of the other tabbed panes can access this file and add and delete data from it, i.e. the file may have changed.

So I would like to be able to say sonething like:

everytime this visual pane is selected,

update the information on it/redisplay it.

SO far I haven't found how I can redisplay the pane in this manner....

sasquata at 2007-7-7 16:11:40 > top of Java-index,Desktop,Core GUI APIs...
# 3
Both of camickr's suggestions still seem valid. If you are having trouble be specific with what you are trying to do that is not work, you might need to post some code. But first try the suggestions he gave.
zadoka at 2007-7-7 16:11:40 > top of Java-index,Desktop,Core GUI APIs...
# 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...

sasquata at 2007-7-7 16:11:40 > top of Java-index,Desktop,Core GUI APIs...
# 5

Every time you change a tab, the tab needs to repaint itself. So if your tab isn't updated its because you haven't updated the components on that tab with the new data.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.

camickra at 2007-7-7 16:11:40 > top of Java-index,Desktop,Core GUI APIs...