davidahines
davidahines

Reputation: 4094

How can I refresh a JPanel in a JTabbedPane only if that tab is the one that is visible?

I have a pane that I need to rebuild the contents of and then swap it with the current panel, but only if it's the current tab.

Upvotes: 1

Views: 4956

Answers (1)

Nate W.
Nate W.

Reputation: 9249

You can simply do this:

final int nTabIndex = myTabbedPane.indexOfTabComponent( myPanel );
final boolean bIsVisible = myTabbedPane.isEnabledAt( nTabIndex );
if ( bIsVisible ) {
    // Do stuff with myPanel
    myPanel.repaint();
}

Upvotes: 4

Related Questions