javax.swing.JTabbedPane#getTabCount ( )源码实例Demo

下面列出了javax.swing.JTabbedPane#getTabCount ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FlatLaf   文件: MnemonicHandler.java
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;
}
 
源代码2 项目: netbeans   文件: OptionsPanel.java
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;
            }
        }
    }
}
 
源代码3 项目: netbeans   文件: RefactoringPanelContainer.java
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();
        }
    }
}
 
源代码4 项目: netbeans   文件: RefactoringPanelContainer.java
@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();
    }
}
 
源代码5 项目: rapidminer-studio   文件: ConnectionEditDialog.java
/**
 * 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;
		}
	}
}
 
源代码6 项目: marathonv5   文件: JTabbedPaneJavaElement.java
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;
}
 
源代码7 项目: netbeans   文件: OptionsPanel.java
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;
}
 
源代码8 项目: psychoPATH   文件: PsychoTab.java
/**
 * 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);
    });
}
 
源代码9 项目: netbeans   文件: DiffViewModeSwitcher.java
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);
        }
    }
}
 
源代码10 项目: CodenameOne   文件: BasicOutlookBarUI.java
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;
}
 
源代码11 项目: rapidminer-studio   文件: ConnectionEditDialog.java
/**
 * 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);
}
 
源代码12 项目: JWT4B   文件: JWTSuiteTabController.java
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);
	}
}
 
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()));
    }
}
 
源代码14 项目: gcs   文件: UIUtilities.java
/**
 * 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;
        }
    }
}
 
源代码15 项目: radiance   文件: TabPreviewThread.java
@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();
		}
	}
}
 
源代码16 项目: marathonv5   文件: JTabbedPaneTabJavaElement.java
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;
}
 
源代码17 项目: netbeans   文件: OptionsTest.java
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();
    }
}
 
源代码18 项目: pcgen   文件: InfoTabbedPane.java
/**
 * 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);
	}
}
 
源代码19 项目: TrakEM2   文件: Merger.java
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);
		}
	}});
}
 
源代码20 项目: pcgen   文件: InfoTabbedPane.java
/**
 * 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);
	}
}