2

I'm quite new to event listening and GUI's, so am having trouble figuring this out.

I have a JTabbedPane to which I have added 3 components. These components are JToolBars, which allows me to drag them out of the JTabbedPane into a floating window. This removes the tab from the tabbed pane. When I drag the JToolBar back into the pane, the tab is recreated. However, it now has an incorrect name. The name corresponds to which side of the TabbedPane the ToolBar was docked to; North, South, East or West.

Can anyone recommend a decent way of detecting that a JToolBar has been redocked and then updating the tab title? Thus far I've implemented a change listener on the tabbedPane, but cannot work out a suitable event.

Cheers.

SOLVED: The solution was to use a ContainerListener to detect a component added through the implemented componentAdded method. When a component was added to the JTabbedPane, I called a method to update the tab names with the components name, set via .setName().

public void componentAdded(ContainerEvent added) {
    updateTabs();
}

public void updateTabs() {
    for (int i = 0; i < tabbedPane.getComponents().length; i++) {
        tabbedPane.setTitleAt(i,
                tabbedPane.getComponents()[i].getName());
    }
}
jdn
  • 33
  • 6
  • 2
    welcome to SO pl read [SSCCE](http://http://sscce.org/), your question should motivate to answer not to make bore. – vels4j Nov 17 '12 at 17:10
  • 1
    Here's a related [example](http://stackoverflow.com/a/11949899/230513) to get your [sscce](http://sscce.org/) started. – trashgod Nov 17 '12 at 17:47
  • Thanks guys, sorry for the poor quality of the question, I'm on a deadline at the moment so am being a bit terse. I'll improve this question and solution I found as soon as possible. – jdn Nov 17 '12 at 18:34

1 Answers1

1

The solution was to use a ContainerListener to detect a component added through the implemented componentAdded method. When a component was added to the JTabbedPane, I called a method to update the tab names with the components name, set via .setName().

public void componentAdded(ContainerEvent added) {
    updateTabs();
}

public void updateTabs() {
    for (int i = 0; i < tabbedPane.getComponents().length; i++) {
        tabbedPane.setTitleAt(i,
                tabbedPane.getComponents()[i].getName());
    }
}
jdn
  • 33
  • 6