Java Code Examples for javax.swing.JTabbedPane#getTabCount()

The following examples show how to use javax.swing.JTabbedPane#getTabCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OptionsPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void handleNotFound(String id, String exactCategory, String exactTabTitle) {
    if (!disabledCategories.contains(id)) {
        disabledCategories.add(id);
    }
    JTabbedPane pane = categoryid2tabbedpane.get(id);
    if (categoryid2tabs.get(id) != null && pane != null) {
        for (int i = 0; i < pane.getTabCount(); i++) {
            pane.setEnabledAt(i, false);
        }
    }
    buttons.get(id).setEnabled(false);
    if (disabledCategories.size() == buttons.size()) {
        setCurrentCategory(null, null);
    } else {
        for (String id3 : categoryModel.getCategoryIDs()) {
            if (buttons.get(id3).isEnabled() && ((exactCategory != null && exactCategory.equals(id3)) || (exactCategory == null && exactTabTitle == null))) {
                setCurrentCategory(categoryModel.getCategory(id3), null);
                break;
            }
        }
    }
}
 
Example 2
Source File: MnemonicHandler.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
private static boolean hasMnemonic( Component c ) {
	if( c instanceof JLabel && ((JLabel)c).getDisplayedMnemonicIndex() >= 0 )
		return true;

	if( c instanceof AbstractButton && ((AbstractButton)c).getDisplayedMnemonicIndex() >= 0 )
		return true;

	if( c instanceof JTabbedPane ) {
		JTabbedPane tabPane = (JTabbedPane) c;
		int tabCount = tabPane.getTabCount();
		for( int i = 0; i < tabCount; i++ ) {
			if( tabPane.getDisplayedMnemonicIndexAt( i ) >= 0 )
				return true;
		}
	}

	return false;
}
 
Example 3
Source File: RefactoringPanelContainer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void closeAllButCurrent() {
    Component comp = getComponent(0);
    if (comp instanceof JTabbedPane) {
        JTabbedPane tabs = (JTabbedPane) comp;
        Component current = tabs.getSelectedComponent();
        int tabCount = tabs.getTabCount();
        // #172039: do not use tabs.getComponents()
        Component[] c = new Component[tabCount - 1];
        for (int i = 0, j = 0; i < tabCount; i++) {
            Component tab = tabs.getComponentAt(i);
            if (tab != current) {
                c[j++] = tab;
            }
        }
        for (int i = 0; i < c.length; i++) {
            ((RefactoringPanel) c[i]).close();
        }
    }
}
 
Example 4
Source File: RefactoringPanelContainer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void componentClosed() {
    isVisible = false;
    if (getComponentCount() == 0) {
        return ;
    }
    Component comp = getComponent(0);
    if (comp instanceof JTabbedPane) {
        JTabbedPane pane = (JTabbedPane) comp;
        // #172039: do not use tabs.getComponents()
        Component[] c = new Component[pane.getTabCount()];
        for (int i = 0; i < c.length; i++) {
            c[i] = pane.getComponentAt(i);
        }
        for (int i = 0; i < c.length; i++) {
            ((RefactoringPanel) c[i]).close();
        }
    } else if (comp instanceof RefactoringPanel) {
        ((RefactoringPanel) comp).close();
    }
}
 
Example 5
Source File: DiffViewModeSwitcher.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setupMode (DiffController view) {
    JTabbedPane tabPane = findTabbedPane(view.getJComponent());
    if (tabPane != null) {
        if (!handledViews.containsKey(tabPane)) {
            ChangeListener list = WeakListeners.change(this, tabPane);
            handledViews.put(tabPane, list);
            tabPane.addChangeListener(list);
        }
        if (tabPane.getTabCount() > diffViewMode) {
            tabPane.setSelectedIndex(diffViewMode);
        }
    }
}
 
Example 6
Source File: UIUtilities.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Selects the tab with the specified title.
 *
 * @param pane  The {@link JTabbedPane} to use.
 * @param title The title to select.
 */
public static void selectTab(JTabbedPane pane, String title) {
    int count = pane.getTabCount();
    for (int i = 0; i < count; i++) {
        if (pane.getTitleAt(i).equals(title)) {
            pane.setSelectedIndex(i);
            break;
        }
    }
}
 
Example 7
Source File: TestDataComponent.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private void searchTestData(Object source) {
    JTabbedPane tab = (JTabbedPane) source;
    List<String> tabs = new ArrayList<>();
    for (int i = 0; i < tab.getTabCount() - 1; i++) {
        tabs.add(tab.getTitleAt(i));
    }
    JComboBox combo = new JComboBox(tabs.toArray());
    int option = JOptionPane.showConfirmDialog(null, combo,
            "Go To TestData",
            JOptionPane.DEFAULT_OPTION);
    if (option == JOptionPane.OK_OPTION) {
        tab.setSelectedIndex(tabs.indexOf(combo.getSelectedItem().toString()));
    }
}
 
Example 8
Source File: JWTSuiteTabController.java    From JWT4B with GNU General Public License v3.0 5 votes vote down vote up
public void selectJWTSuiteTab() {
	Component current = this.getUiComponent();
	do {
		current = current.getParent();
	} while (!(current instanceof JTabbedPane));

	JTabbedPane tabPane = (JTabbedPane) current;
	for (int i = 0; i < tabPane.getTabCount(); i++) {
		if (tabPane.getTitleAt(i).equals(this.getTabCaption()))
			tabPane.setSelectedIndex(i);
	}
}
 
Example 9
Source File: ConnectionEditDialog.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Show a specific tab, to be found via the index. Fails quietly.
 *
 * @param index
 * 		the index of the tab to be selected
 */
public void showTab(int index) {
	JTabbedPane tabPane = (JTabbedPane) mainGUI;
	if (index < 0 || index >= tabPane.getTabCount()) {
		return;
	}
	tabPane.setSelectedIndex(index);
}
 
Example 10
Source File: BasicOutlookBarUI.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public int tabForCoordinate(JTabbedPane pane, int x, int y) {
  int index = -1;
  for (int i = 0, c = pane.getTabCount(); i < c; i++) {
    if (pane.getComponentAt(i).contains(x, y)) {
      index = i;
      break;
    }
  }
  return index;
}
 
Example 11
Source File: PsychoTab.java    From psychoPATH with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Find our tab index within Burp's JTabbedPane. Setup an activation
 * listener that resets the title colour to black.
 */
public void findTab() {
    if(tabIndex != null)
        return;
    tabPane = (JTabbedPane) psychoPanel.getParent();
    if(tabPane == null)
        return;
    for(int i = 0; i < tabPane.getTabCount(); i++)
        if(Objects.equals(tabPane.getTitleAt(i), getTabCaption()))
            tabIndex = i;
    tabPane.addChangeListener((ChangeEvent e1) -> {
        if(tabPane.getSelectedIndex() == tabIndex)
            tabPane.setBackgroundAt(tabIndex, Color.BLACK);
    });
}
 
Example 12
Source File: OptionsPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private int getNextEnabledTabIndex(JTabbedPane pane, int currentIndex) {
    for (int i = currentIndex + 1; i < pane.getTabCount(); i++) {
        if(pane.isEnabledAt(i)) {
            return i;
        }
    }
    for (int i = 0; i < currentIndex; i++) {
        if(pane.isEnabledAt(i)) {
            return i;
        }
    }
    return -1;
}
 
Example 13
Source File: JTabbedPaneJavaElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static String[][] getContent(JTabbedPane component) {
    int nItems = component.getTabCount();
    String[][] content = new String[1][nItems];
    for (int i = 0; i < nItems; i++) {
        content[0][i] = JTabbedPaneTabJavaElement.getText(component, i);
    }
    return content;
}
 
Example 14
Source File: ConnectionEditDialog.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Show a specific tab, to be found via the title. The title is already present resolved from I18N so the result
 * from {@link ConnectionI18N#getConnectionGUILabel(String, Object...)} is required here. Fails quietly.
 *
 * @param name
 * 		value of the I18N key for connection GUI label
 */
public void showTab(String name) {
	if (name == null || !(mainGUI instanceof JTabbedPane)) {
		return;
	}

	JTabbedPane tabPane = (JTabbedPane) mainGUI;
	for (int i = 0; i < tabPane.getTabCount(); i++) {
		if (name.equals(tabPane.getTitleAt(i))) {
			tabPane.setSelectedIndex(i);
			break;
		}
	}
}
 
Example 15
Source File: OptionsTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testOptionsCategories() {
    OptionsOperator oo = OptionsOperator.invoke();//open options

    Component optionsPanel = oo.findSubComponent(getCompChooser("org.netbeans.modules.options.OptionsPanel"));
    //we need container to be able to traverse inside   
    Container optionsContainer = ContainerOperator.findContainerUnder(optionsPanel);
    ArrayList<Component> optionsCategories = new ArrayList<Component>();
    optionsCategories.addAll(Utilities.findComponentsInContainer(
            optionsContainer,
            getCompChooser("org.netbeans.modules.options.OptionsPanel$CategoryButton"),
            true));
    optionsCategories.addAll(Utilities.findComponentsInContainer(
            optionsContainer,
            getCompChooser("org.netbeans.modules.options.OptionsPanel$NimbusCategoryButton"),
            true));

    NbMenuItem ideOptions = new NbMenuItem(getName());//let store it in NbMenuItem TODO: refactor to make it simplier
    ArrayList<NbMenuItem> categories = new ArrayList<NbMenuItem>();
    NbMenuItem miscCategory = null;//remember the miscellanous because you will add the subcategories to it
    for (Component component : optionsCategories) {
        NbMenuItem optionsCategory = new NbMenuItem(((JLabel) component).getText());
        categories.add(optionsCategory);
        if (optionsCategory.getName().equals("Miscellaneous")) {//NOI18N
            miscCategory = optionsCategory;
        }
    }
    ideOptions.setSubmenu(categories);

    oo.selectMiscellaneous();//switch to Miscelenous

    JTabbedPane miscellaneousPanel = (JTabbedPane) oo.findSubComponent(getCompChooser("javax.swing.JTabbedPane"));

    ArrayList<NbMenuItem> miscCategories = new ArrayList<NbMenuItem>();
    for (int i = 0; i < miscellaneousPanel.getTabCount(); i++) {
        NbMenuItem miscCategoryItem = new NbMenuItem();
        miscCategoryItem.setName(miscellaneousPanel.getTitleAt(i));//
        miscCategories.add(miscCategoryItem);
    }
    miscCategory.setSubmenu(miscCategories);

    //load categories order from golden file
    LogFiles logFiles = new LogFiles();
    PrintStream ideFileStream = null;
    PrintStream goldenFileStream = null;

    try {
        ideFileStream = logFiles.getIdeFileStream();
        goldenFileStream = logFiles.getGoldenFileStream();

        //read the golden file
        NbMenuItem goldenOptions = Utilities.parseSubTreeByLines(getGoldenFile("options", "options-categories").getAbsolutePath());
        goldenOptions.setName(getName());

        //make a diff
        Utilities.printMenuStructure(ideFileStream, ideOptions, "  ", 100);
        Utilities.printMenuStructure(goldenFileStream, goldenOptions, "  ", 100);

        Manager.getSystemDiff().diff(logFiles.pathToIdeLogFile, logFiles.pathToGoldenLogFile, logFiles.pathToDiffLogFile);
        String message = Utilities.readFileToString(logFiles.pathToDiffLogFile);
        assertFile(message, logFiles.pathToGoldenLogFile, logFiles.pathToIdeLogFile, logFiles.pathToDiffLogFile);
    } catch (IOException ex) {
        ex.printStackTrace(System.err);
    } finally {
        ideFileStream.close();
        goldenFileStream.close();
    }
}
 
Example 16
Source File: JTabbedPaneTabJavaElement.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private boolean makeTabVisible(JTabbedPane tp, int selectedTab) {
    validateTab();
    if (!(tp.getUI() instanceof BasicTabbedPaneUI)) {
        try {
            EventQueueWait.call(tp, "setSelectedIndex", selectedTab);
        } catch (NoSuchMethodException e) {
            throw new InvalidElementStateException(
                    "Unable to call setSelectedIndex on JTabbedPane. selectedTab = " + selectedTab, e);
        }
        return true;
    }
    boolean isVisible = false;
    int n = tp.getTabCount();
    int loopCount = n;
    Action backward = tp.getActionMap().get("scrollTabsBackwardAction");
    Action forward = tp.getActionMap().get("scrollTabsForwardAction");
    while (!isVisible && loopCount-- > 0) {
        int firstVisibleTab = -1, lastVisibleTab = -1;
        for (int i = 0; i < n; i++) {
            Rectangle tabBounds = tp.getBoundsAt(i);
            int tabForCoordinate = tp.getUI().tabForCoordinate(tp, tabBounds.x + tabBounds.width / 2,
                    tabBounds.y + tabBounds.height / 2);
            if (tabForCoordinate != -1) {
                if (firstVisibleTab == -1) {
                    firstVisibleTab = tabForCoordinate;
                }
                lastVisibleTab = tabForCoordinate;
            }
        }
        isVisible = firstVisibleTab <= selectedTab && selectedTab <= lastVisibleTab;
        if (isVisible) {
            continue;
        }
        if (selectedTab < firstVisibleTab) {
            backward.actionPerformed(new ActionEvent(tp, ActionEvent.ACTION_PERFORMED, ""));
        } else {
            forward.actionPerformed(new ActionEvent(tp, ActionEvent.ACTION_PERFORMED, ""));
        }
    }
    return isVisible;
}
 
Example 17
Source File: InfoTabbedPane.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Switch the current tab to be the one named, possibly including a sub tab
 * and then advise the user of the item to be done. generally the tab will
 * handle this but a fallback of a dialog will be used if the tab can't do
 * the advising.
 *
 * @param dest An arry of the tab name, the field name and optionally the
 * sub tab name.
 */
private void switchTabsAndAdviseTodo(String[] dest)
{
	Tab tab = Tab.valueOf(dest[0]);
	String tabName = currentCharacter.getDataSet().getGameMode().getTabName(tab);

	Component selTab = null;
	for (int i = 0; i < getTabCount(); i++)
	{
		if (tabName.equals(getTitleAt(i)))
		{
			setSelectedIndex(i);
			selTab = getComponent(i);
			break;
		}
	}
	if (selTab == null)
	{
		Logging.errorPrint("Failed to find tab " + tabName); //$NON-NLS-1$
		return;
	}

	if (selTab instanceof JTabbedPane && dest.length > 2)
	{
		JTabbedPane tabPane = (JTabbedPane) selTab;
		for (int i = 0; i < tabPane.getTabCount(); i++)
		{
			if (dest[2].equals(tabPane.getTitleAt(i)))
			{
				tabPane.setSelectedIndex(i);
				break;
			}
		}
	}

	if (selTab instanceof TodoHandler)
	{
		((TodoHandler) selTab).adviseTodo(dest[1]);
	}
	else
	{
		String message = LanguageBundle.getFormattedString("in_todoUseField", dest[1]); //$NON-NLS-1$
		JOptionPane.showMessageDialog(selTab, message, LanguageBundle.getString("in_tipsString"), //$NON-NLS-1$
			JOptionPane.INFORMATION_MESSAGE);
	}
}
 
Example 18
Source File: Merger.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
private static void makeGUI(final Project p1, final Project p2,
		HashSet<ZDisplayable> empty1, HashSet<ZDisplayable> empty2,
		HashMap<Displayable,List<Change>> matched,
		HashSet<ZDisplayable> unmatched1,
		HashSet<ZDisplayable> unmatched2) {

	final ArrayList<Row> rows = new ArrayList<Row>();
	for (Map.Entry<Displayable,List<Change>> e : matched.entrySet()) {
		for (Change c : e.getValue()) {
			rows.add(new Row(c));
		}
		if (e.getValue().size() > 1) {
			Utils.log("More than one assigned to " + e.getKey());
		}
	}
	JTabbedPane tabs = new JTabbedPane();

	final Table table = new Table();
	tabs.addTab("Matched", new JScrollPane(table));

	JTable tu1 = createTable(unmatched1, "Unmatched 1", p1, p2);
	JTable tu2 = createTable(unmatched2, "Unmatched 2", p1, p2);
	JTable tu3 = createTable(empty1, "Empty 1", p1, p2);
	JTable tu4 = createTable(empty2, "Empty 2", p1, p2);

	tabs.addTab("Unmatched 1", new JScrollPane(tu1));
	tabs.addTab("Unmatched 2", new JScrollPane(tu2));
	tabs.addTab("Empty 1", new JScrollPane(tu3));
	tabs.addTab("Empty 2", new JScrollPane(tu4));

	for (int i=0; i<tabs.getTabCount(); i++) {
		if (null == tabs.getTabComponentAt(i)) {
			Utils.log2("null at " + i);
			continue;
		}
		tabs.getTabComponentAt(i).setPreferredSize(new Dimension(1024, 768));
	}

	String xml1 = new File(((FSLoader)p1.getLoader()).getProjectXMLPath()).getName();
	String xml2 = new File(((FSLoader)p2.getLoader()).getProjectXMLPath()).getName();
	JFrame frame = new JFrame("1: " + xml1 + "  ||  2: " + xml2);
	tabs.setPreferredSize(new Dimension(1024, 768));
	frame.getContentPane().add(tabs);
	frame.pack();
	frame.setVisible(true);

	// so the bullshit starts: any other way to set the model fails, because it tries to render it while setting it
	SwingUtilities.invokeLater(new Runnable() { public void run() {
		table.setModel(new Model(rows));
		CustomCellRenderer cc = new CustomCellRenderer();
		for (int i=0; i<Row.COLUMNS; i++) {
			table.setDefaultRenderer(table.getColumnClass(i), cc);
		}
	}});
}
 
Example 19
Source File: InfoTabbedPane.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Switch the current tab to be the one named, possibly including a sub tab
 * and then advise the user of the item to be done. generally the tab will
 * handle this but a fallback of a dialog will be used if the tab can't do
 * the advising.
 *
 * @param dest An arry of the tab name, the field name and optionally the
 * sub tab name.
 */
private void switchTabsAndAdviseTodo(String[] dest)
{
	Tab tab = Tab.valueOf(dest[0]);
	String tabName = currentCharacter.getDataSet().getGameMode().getTabName(tab);

	Component selTab = null;
	for (int i = 0; i < getTabCount(); i++)
	{
		if (tabName.equals(getTitleAt(i)))
		{
			setSelectedIndex(i);
			selTab = getComponent(i);
			break;
		}
	}
	if (selTab == null)
	{
		Logging.errorPrint("Failed to find tab " + tabName); //$NON-NLS-1$
		return;
	}

	if (selTab instanceof JTabbedPane && dest.length > 2)
	{
		JTabbedPane tabPane = (JTabbedPane) selTab;
		for (int i = 0; i < tabPane.getTabCount(); i++)
		{
			if (dest[2].equals(tabPane.getTitleAt(i)))
			{
				tabPane.setSelectedIndex(i);
				break;
			}
		}
	}

	if (selTab instanceof TodoHandler)
	{
		((TodoHandler) selTab).adviseTodo(dest[1]);
	}
	else
	{
		String message = LanguageBundle.getFormattedString("in_todoUseField", dest[1]); //$NON-NLS-1$
		JOptionPane.showMessageDialog(selTab, message, LanguageBundle.getString("in_tipsString"), //$NON-NLS-1$
			JOptionPane.INFORMATION_MESSAGE);
	}
}
 
Example 20
Source File: TabPreviewThread.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void run() {
	while (!this.stopRequested) {
		try {
			// System.out.println(System.currentTimeMillis() + " Polling");
			int delay = 500;
			List<Deltable> expired = this.dequeueTabPreviewRequest(delay);
			for (Deltable dExpired : expired) {
				final TabPreviewInfo nextPreviewInfo = (TabPreviewInfo) dExpired;
				final JTabbedPane jtp = nextPreviewInfo.tabPane;
				if (jtp == null)
					continue;
				final TabPreviewPainter previewPainter = TabPreviewUtilities
						.getTabPreviewPainter(jtp);
				final int tabCount = jtp.getTabCount();

				if (nextPreviewInfo.toPreviewAllTabs) {
					// The call to start() is only relevant for the
					// preview of all tabs.
					SwingUtilities.invokeLater(() ->
							nextPreviewInfo.previewCallback.start(jtp, 
									jtp.getTabCount(), nextPreviewInfo));

					for (int i = 0; i < tabCount; i++) {
						final int index = i;
						SwingUtilities.invokeLater(() -> 
								getSingleTabPreviewImage(jtp, previewPainter, 
										nextPreviewInfo, index));
					}
				} else {
					SwingUtilities.invokeLater(() -> 
						getSingleTabPreviewImage(jtp, previewPainter,
								nextPreviewInfo, nextPreviewInfo.tabIndexToPreview));
				}

				if (previewPainter.toUpdatePeriodically(jtp)) {
					TabPreviewInfo cyclePreviewInfo = new TabPreviewInfo();
					// copy all the fields from the currently processed
					// request
					cyclePreviewInfo.tabPane = nextPreviewInfo.tabPane;
					cyclePreviewInfo.tabIndexToPreview = nextPreviewInfo.tabIndexToPreview;
					cyclePreviewInfo.toPreviewAllTabs = nextPreviewInfo.toPreviewAllTabs;
					cyclePreviewInfo.previewCallback = nextPreviewInfo.previewCallback;
					cyclePreviewInfo.setPreviewWidth(nextPreviewInfo.getPreviewWidth());
					cyclePreviewInfo.setPreviewHeight(nextPreviewInfo.getPreviewHeight());
					cyclePreviewInfo.initiator = nextPreviewInfo.initiator;

					// schedule it to app-specific delay
					cyclePreviewInfo.setDelta(previewPainter.getUpdateCycle(cyclePreviewInfo.tabPane));

					// queue the new request
					this.queueTabPreviewRequest(cyclePreviewInfo);
				}
			}
			Thread.sleep(delay);
		} catch (InterruptedException ie) {
			ie.printStackTrace();
		}
	}
}