Bart van Heukelom
Bart van Heukelom

Reputation: 44134

Refresh tab name from result of getName()

I'm adding a custom component to a JTabbedPane. The title of the tab is determined by getName() in the component. Now at some point the result of getName() changes, but the tab title is not automatically refreshed (as can be expected). How can I make it so?

Upvotes: 3

Views: 242

Answers (1)

JB Nizet
JB Nizet

Reputation: 692291

Each time your component's name is changed, it could throw a PropertyChangeEvent. When the component is added to the tabbed pane, you could add a PropertyChangeListener to the component, listening for changes of its name property, and updating the tab name accordingly.

Don't forget to remove the listener when the component is removed from the tabbed pane, though.

Upvotes: 3

Related Questions