0

I am using a JideTabbedPane. which extends JTabbedPane. After a user edits the name of a tab, I want to check whether the name meets certain criteria, e.g. the name must not be an empty string. If it doesn't meet the criteria, the old name of the tab should be used.

I used a TabEditingListener to try to accomplish this task, but it didn't work. Here is what I wrote:

  addTabEditingListener(new TabEditingListener() {
    public void editingStopped(TabEditingEvent event) {
      if (event.getNewTitle().isEmpty()) {
        setTitleAt(event.getTabIndex(), event.getOldTitle());
      }
    }
  }

Any ideas will be greatly appreciated.

BJ Dela Cruz
  • 5,194
  • 13
  • 51
  • 84
  • You might want to specify the 'did not work' part. Is your listener never called ? Is the title in the event not set ? Do you get any exceptions ? ... – Robin Apr 10 '12 at 21:10
  • @Robin The listener gets called, but the title never gets set. No exceptions. Nothing happens. – BJ Dela Cruz Apr 10 '12 at 21:12
  • did you have got the same EDT issue as in the [JideForum](http://www.jidesoft.com/forum/viewtopic.php?f=18&t=12472&p=61402&hilit=JideTabbedPane#p61402) – mKorbel Apr 10 '12 at 21:39
  • @mKorbel I didn't get an EDT issue. – BJ Dela Cruz Apr 11 '12 at 05:54

2 Answers2

0

I am not familiar with the JideTabbedPane so there might be better solutions and mechanisms. But the JTabbedPane#setTitleAt method which I guess is called after editing the title fires a PropertyChangeEvent for the indexForTitle property according to the source code. You can listen for that event and perform the validation.

Robin
  • 36,233
  • 5
  • 47
  • 99
0

You should have an else statement pretty much saying that if it isn't invalid, set the text as what they entered.

Shawn Shroyer
  • 901
  • 1
  • 8
  • 18