JYTabbedPane Features in SyntheticaAddons V1.6(10:54, 10. Nov. 2011)

SyntheticaAddons V1.6.0 provides some new JYTabbedPane features. So let's take a look at these new features and find out how to use them in your application.

PlusButton support to add new tabs

JYTabbedPane PlusButton

The PlusButton isn't shown by default and has to be enabled by calling JYTabbedPane#setShowPlusButton(true). To let you control how the new Tabs will be created you additionaly have to provide an "addTab" action and put the action into the action map just like in the example below.

final JYTabbedPane tabbedPane = new JYTabbedPane();
tabbedPane.getActionMap().put("addTab", new AbstractAction(){
  public void actionPerformed(ActionEvent evt)
  {
    //add tab and content
    tabbedPane.addTab("New Tab", createTabbedPaneContent());    
    //move tab after selected tab and select the new tab
    if (tabPane.getTabCount() > 1)
    {  
      int index = tabPane.getSelectedIndex() + 1;
      tabbedPane.moveTab(tabPane.getTabCount() - 1, index);
      tabbedPane.setSelectedIndex(index);
    }  
  }
});
tabbedPane.setShowPlusButton(true);

Editable tabs

JYTabbedPane PlusButton

Tabs are non-editable by default. However, JYTabbedPane#setTabsEditable(true) is the related method to make tabs editable on double-click. If you are interested in tab text changes, add a PropertyChangeListener to the tabbed pane and filter events for the property name "title".

Custom Close Button Strategy

JYTabbedPane CustomCloseButtonStrategy

Sometimes it's necessary to use a custom strategy e.g. to make one or more tabs non-closable. By setting the custom ICloseButtonStrategy below there's no way for the user to close the first tab.

JYTabbedPane tabbedPane = new JYTabbedPane();
tabbedPane.setCloseButtonStrategy(new ICloseButtonStrategy()
{      
  public boolean isButtonVisible(JYTabbedPane tabbedPane, Tab tab)
  {
    return tab.getTabIndex()) > 0;
  }
});

Tab History Support

The default behavior on tab close is to automatically select the next available tab in the tab row. By enabling tab history JYTabbedPane is able to remember the tab which was selected before the currently selected tab and restores the tab on tab close. This feature improves usability for closable tabs.

JYTabbedPane TabHistory

The example below demonstrates how to enable tab history.

JYTabbedPane tabbedPane = new JYTabbedPane();
tabbedPane.setTabHistoryEnabled(true);
tabbedPane.setCloseButtonStrategy(CloseButtonStrategy.ALL_TABS);

 

Related Posts

How to customize a JYTabbedPane component
How To Set A Custom Close Tab Action
Customization - How to apply a Firefox style to a JTabbedPane