我需要一個方法,可以在指定的索引處插入新的選項卡和選項卡後,該索引應該向右移動。如何在現有標籤之間插入新標籤而不刪除任何標籤?
我不想刪除新標籤後的所有標籤並將其插回。我只想添加現有的新選項卡。
代碼:
public class MainTabbedPane extends JTabbedPane {
private SyntaxHighlighterManager syntaxHighlighterManager;
private Map<Integer, Rectangle> tabsBounds = new HashMap<>();
public MainTabbedPane() {
this.syntaxHighlighterManager = SyntaxHighlighterManager.getInstance();
Map<String, Action> actions = MainFrame.getInstance().getActions();
Action closeTabAction = actions.get(CloseTabAction.CLOSE_TAB);
Action closeAllTabsAction = actions.get(CloseAllTabsAction.CLOSE_ALL_TABS);
Action closeAllTabsButThis = actions.get(CloseAllTabsButThisAction.CLOSE_ALL_BUT_THIS);
super.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
(KeyStroke) closeTabAction.getValue(Action.ACCELERATOR_KEY), CloseTabAction.CLOSE_TAB);
super.getActionMap().put(CloseTabAction.CLOSE_TAB, closeTabAction);
super.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
(KeyStroke) closeAllTabsAction.getValue(Action.ACCELERATOR_KEY), CloseAllTabsAction.CLOSE_ALL_TABS);
super.getActionMap().put(CloseAllTabsAction.CLOSE_ALL_TABS, closeAllTabsAction);
super.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
(KeyStroke) closeAllTabsButThis.getValue(Action.ACCELERATOR_KEY),
CloseAllTabsButThisAction.CLOSE_ALL_BUT_THIS);
super.getActionMap().put(CloseAllTabsButThisAction.CLOSE_ALL_BUT_THIS, closeAllTabsButThis);
// super.setUI(new MainTabUI());
// TabReorderHandler.enableReordering(this);
}
/**
* Central method for adding new tab.
*
* @param title
* @param fileViewer
* @param tip
*/
private void addNewTab(String title, Container fileViewer, String tip) {
if (fileViewer != null) {
super.addTab(title, null, fileViewer, tip);
// icon is set in tabComponent MainTabComponent
super.setTabComponentAt(super.getTabCount() - 1, new MainTabComponent(title, this));
tabsBounds.put(super.getTabCount() - 1, super.getUI().getTabBounds(this, super.getTabCount() - 1));
}
}
方法addNewTab
增加了新的選項卡。
謝謝!
顯示你的代碼,你創建tabedpane – raj
tabbedPane.setTabComponentAt(0,新的JLabel( 「新標籤」 )); – raj
我需要添加組件和選項卡組件。 –