Reputation: 1935
When I use setSelectedComponent
or setSelectedIndex
on a JTabbedPane
object, the panel always comes up in my UI. However, sometimes the tab associated with the panel remains hidden. In other words, the tab does not scroll to a visible portion of the tabbed pane.
How can I fix this? I have tried the cheesy select one index, then select desired index, as well as several other more elegant things, but arrrrgh!!
Help me if you can.
Thanks, Todd
Upvotes: 1
Views: 1822
Reputation: 16518
Here is a patter you can use if you have a method that alters swing components, or their models and so must be called on the EDT, but may be called from a background thread. This ensures func always runs on the EDT:
void func(final Type1 arg1, final Type2 arg2) {
if (!SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
func(arg1, arg2);
}
});
return;
}
// method code goes here
}
Upvotes: 1
Reputation: 17359
I think your call is not done on EDT. Wrap it with SwingUtilities.invokeLater
Upvotes: 2