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

The following examples show how to use javax.swing.JTabbedPane#setSelectedIndex() . 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: TestDataComponent.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
public Boolean navigateToTestData(String sheetName, String columnName) {
    if (envTab.getSelectedComponent() instanceof JTabbedPane) {
        JTabbedPane tab = (JTabbedPane) envTab.getSelectedComponent();
        for (int i = 0; i < tab.getTabCount(); i++) {
            if (tab.getComponentAt(i) instanceof TestDataTablePanel) {
                TestDataTablePanel tdPanel = (TestDataTablePanel) tab.getComponentAt(i);
                if (tdPanel.std.getName().equals(sheetName)) {
                    int colIndex = tdPanel.std.getColumnIndex(columnName);
                    if (colIndex != -1) {
                        tab.setSelectedIndex(i);
                        tdPanel.table.selectColumn(colIndex);
                        return true;
                    }
                    break;
                }
            }
        }
    }
    return false;
}
 
Example 2
Source File: CloseActionHandler.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {

    JTabbedPane ntp = getNumberedTabbedPane();

    int index = ntp.indexOfTab(getTabName());
    if (index >= 0) {
        if (ntp.getTabCount() > 2 && index == ntp.getTabCount() - 2) {
            ntp.setSelectedIndex(index - 1);
        }
        ManualHttpRequestEditorPanel currentEditor =
                (ManualHttpRequestEditorPanel) ntp.getComponentAt(index);
        currentEditor.beforeClose();
        currentEditor.saveConfig();
        ntp.removeTabAt(index);
    }
}
 
Example 3
Source File: TestDataComponent.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
private MouseAdapter onAddNewTDTab() {
    return new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent me) {
            JTabbedPane tabbedPane = (JTabbedPane) me.getSource();
            if (tabbedPane.getSelectedIndex() != -1 && getSelectedData() == null) {
                Rectangle rect = tabbedPane.getUI().
                        getTabBounds(tabbedPane, tabbedPane.getSelectedIndex());
                if (rect.contains(me.getPoint())) {
                    tabbedPane.setSelectedIndex(tabbedPane.getSelectedIndex() - 1);
                    addNewTestData(tabbedPane);
                }
            }
        }
    };
}
 
Example 4
Source File: Test4234761.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JColorChooser chooser = new JColorChooser(COLOR);
    JDialog dialog = Test4177735.show(chooser);

    PropertyChangeListener listener = new Test4234761();
    chooser.addPropertyChangeListener("color", listener); // NON-NLS: property name

    JTabbedPane tabbedPane = (JTabbedPane) chooser.getComponent(0);
    tabbedPane.setSelectedIndex(1); // HSB tab index

    if (!chooser.getColor().equals(COLOR)) {
        listener.propertyChange(null);
    }
    dialog.dispose();
}
 
Example 5
Source File: TestDataComponent.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private void closeTestData(Object source) {
    JTabbedPane tab = (JTabbedPane) source;
    TestDataTablePanel panel = getSelectedData();
    if (!panel.isGlobalData) {
        int index = tab.getSelectedIndex();
        tab.setSelectedIndex(index - 1);
        tab.removeTabAt(index);
    }
}
 
Example 6
Source File: DefaultPolarPlotEditor.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a tabbed pane for editing the plot attributes.
 * 
 * @param plot  the plot.
 * 
 * @return A tabbed pane. 
 */
@Override
protected JTabbedPane createPlotTabs(Plot plot) {
    JTabbedPane tabs = super.createPlotTabs(plot);
    // TODO find a better localization key
    tabs.insertTab(localizationResources.getString("General1"), null, 
            createPlotPanel(), null, 0);
    tabs.setSelectedIndex(0);
    return tabs;
}
 
Example 7
Source File: Test4234761.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JColorChooser chooser = new JColorChooser(COLOR);
    JDialog dialog = Test4177735.show(chooser);

    PropertyChangeListener listener = new Test4234761();
    chooser.addPropertyChangeListener("color", listener); // NON-NLS: property name

    JTabbedPane tabbedPane = (JTabbedPane) chooser.getComponent(0);
    tabbedPane.setSelectedIndex(1); // HSB tab index

    if (!chooser.getColor().equals(COLOR)) {
        listener.propertyChange(null);
    }
    dialog.dispose();
}
 
Example 8
Source File: DialogEditCodeNodeComment.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the GUI of the dialog.
 *
 * @param initialTab
 */
private void createGui(final InitialTab initialTab) {
  final JTabbedPane tab = new JTabbedPane();

  tab.add("Global Line Comments", m_globalLineCommentsPanel);
  tab.add("Local Line Comments", m_localLineCommentsPanel);
  tab.add("Node Comments", m_commentsPanel);
  tab.add("Function Comments", m_functionCommentsPanel);

  add(tab, BorderLayout.CENTER);
  add(new OKButtonPanel(this), BorderLayout.SOUTH);
  pack();

  switch (initialTab) {
    case GlobalLineComments:
      tab.setSelectedIndex(0);
      break;
    case LocalLineComments:
      tab.setSelectedIndex(1);
      break;
    case LocalNodeComments:
      tab.setSelectedIndex(2);
      m_commentsPanel.focusLocalField();
      break;
    case GlobalNodeComments:
      tab.setSelectedIndex(2);
      m_commentsPanel.focusGlobalField();
      break;
    case FunctionComments:
      tab.setSelectedIndex(3);
      m_functionCommentsPanel.focusGlobalField();
      break;
    default:
      throw new IllegalStateException("IE00681: Unknown initial tab");
  }
}
 
Example 9
Source File: DefaultPolarPlotEditor.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a tabbed pane for editing the plot attributes.
 * 
 * @param plot  the plot.
 * 
 * @return A tabbed pane. 
 */
@Override
protected JTabbedPane createPlotTabs(Plot plot) {
    JTabbedPane tabs = super.createPlotTabs(plot);
    // TODO find a better localization key
    tabs.insertTab(localizationResources.getString("General1"), null, 
            createPlotPanel(), null, 0);
    tabs.setSelectedIndex(0);
    return tabs;
}
 
Example 10
Source File: Test4234761.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JColorChooser chooser = new JColorChooser(COLOR);
    JDialog dialog = Test4177735.show(chooser);

    PropertyChangeListener listener = new Test4234761();
    chooser.addPropertyChangeListener("color", listener); // NON-NLS: property name

    JTabbedPane tabbedPane = (JTabbedPane) chooser.getComponent(0);
    tabbedPane.setSelectedIndex(1); // HSB tab index

    if (!chooser.getColor().equals(COLOR)) {
        listener.propertyChange(null);
    }
    dialog.dispose();
}
 
Example 11
Source File: DefaultDiffControllerProviderTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDifferenceCount () throws Exception {
    int dc = simple.getDifferenceCount();
    assertEquals(3, dc);

    // as default, the graphical view is displayed and the diff count is the same as in the old-style diff view
    dc = enhanced.getDifferenceCount();
    assertEquals(3, dc);
    JTabbedPane c = findTabbedPane(enhanced.getJComponent());

    // switching to the textual view
    final boolean[] finished = new boolean[1];
    enhanced.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (DiffController.PROP_DIFFERENCES.equals(evt.getPropertyName())) {
                finished[0] = true;
            }
        }
    });
    c.setSelectedIndex(1);
    dc = enhanced.getDifferenceCount();
    // zero differences for the textual diff view
    // it shows no differences, displays the diff as a whole
    assertEquals(0, dc);
    // and it should fire an event about differences being changed so clients can refresh navigation button etc.
    for (int i = 0; i < 5 && !finished[0]; ++i) {
        Thread.sleep(1000);
    }
    assertTrue(finished[0]);
}
 
Example 12
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 13
Source File: Test4234761.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JColorChooser chooser = new JColorChooser(COLOR);
    JDialog dialog = Test4177735.show(chooser);

    PropertyChangeListener listener = new Test4234761();
    chooser.addPropertyChangeListener("color", listener); // NON-NLS: property name

    JTabbedPane tabbedPane = (JTabbedPane) chooser.getComponent(0);
    tabbedPane.setSelectedIndex(1); // HSB tab index

    if (!chooser.getColor().equals(COLOR)) {
        listener.propertyChange(null);
    }
    dialog.dispose();
}
 
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: Test4234761.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JColorChooser chooser = new JColorChooser(COLOR);
    JDialog dialog = Test4177735.show(chooser);

    PropertyChangeListener listener = new Test4234761();
    chooser.addPropertyChangeListener("color", listener); // NON-NLS: property name

    JTabbedPane tabbedPane = (JTabbedPane) chooser.getComponent(0);
    tabbedPane.setSelectedIndex(1); // HSB tab index

    if (!chooser.getColor().equals(COLOR)) {
        listener.propertyChange(null);
    }
    dialog.dispose();
}
 
Example 16
Source File: Test4234761.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JColorChooser chooser = new JColorChooser(COLOR);
    JDialog dialog = Test4177735.show(chooser);

    PropertyChangeListener listener = new Test4234761();
    chooser.addPropertyChangeListener("color", listener); // NON-NLS: property name

    JTabbedPane tabbedPane = (JTabbedPane) chooser.getComponent(0);
    tabbedPane.setSelectedIndex(1); // HSB tab index

    if (!chooser.getColor().equals(COLOR)) {
        listener.propertyChange(null);
    }
    dialog.dispose();
}
 
Example 17
Source File: ControlPanel.java    From gepard with MIT License 4 votes vote down vote up
public ControlPanel(Controller ictrl) {

		// store controller
		ctrl = ictrl;

		// load substitution matrices from XML file
		try {
			substMatrices = SubstMatrixList.getInstance().getMatrixFiles();
		} catch (Exception e) {
			ClientGlobals.errMessage("Could not open substitution matrix list. " + "The 'matrices/' subfolder seems to be corrupted");
			System.exit(1);
		}

		// sequences panel
		JPanel localTab = generateLocalTab();

		seqTabs = new JTabbedPane();
		// add sequence panes
		seqTabs.addTab("Sequences", localTab);
		seqTabs.addChangeListener(this);

		// function panel
		JPanel functPanel = generateFunctionPanel();

		// options panel
		JPanel plotOptTab = generatePlotOptTab();
		JPanel miscTab = generateMiscTab();
		dispTab = generateDispTab();

		optTabs = new JTabbedPane();
		optTabs.setFont(MAIN_FONT);
		// optTabs.setBorder(BorderFactory.createEmptyBorder());
		optTabs.addTab("Plot", plotOptTab);
		optTabs.addTab("Misc", miscTab);
		optTabs.addTab("Display", dispTab);
		optTabs.setSelectedIndex(0);

		// create layout
		seqTabs.setAlignmentX(Component.LEFT_ALIGNMENT);
		optTabs.setAlignmentX(Component.LEFT_ALIGNMENT);
		btnGo.setAlignmentX(Component.LEFT_ALIGNMENT);
		functPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
		JPanel fixedBox = new JPanel();
		fixedBox.setLayout(new BoxLayout(fixedBox, BoxLayout.Y_AXIS));
		// fixedBox.setLayout(new GridBagLayout());
		fixedBox.add(Box.createRigidArea(new Dimension(0, 3)));
		fixedBox.add(seqTabs);
		fixedBox.add(Box.createRigidArea(new Dimension(0, 10)));
		fixedBox.add(functPanel);
		// fixedBox.add(Box.createRigidArea(new Dimension(0,10)));

		fixedBox.add(Box.createRigidArea(new Dimension(0, 10)));
		fixedBox.add(optTabs);

		seqTabs.setPreferredSize(new Dimension(1, SEQ_HEIGHT));
		functPanel.setPreferredSize(new Dimension(1, FUNCT_HEIGHT));
		optTabs.setPreferredSize(new Dimension(1, OPT_HEIGHT));

		// dummy panel which pushes the go button to the bottom of the window
		JPanel panelQuit = new JPanel(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 0;
		c.gridy = 0;
		c.weightx = 1;
		c.weighty = 1000;
		panelQuit.add(new JLabel(""), c);
		c.gridy++;
		c.weighty = 1;
		c.insets = new Insets(0, HOR_MARGIN + QUIT_BTN_HOR_MARGIN, BELOW_QUIT_BTN, HOR_MARGIN + QUIT_BTN_HOR_MARGIN);
		panelQuit.add(btnQuit = new JButton("Quit"), c);

		btnQuit.setPreferredSize(new Dimension(1, QUIT_BTN_HEIGHT));

		setLayout(new BorderLayout());
		add(fixedBox, BorderLayout.NORTH);
		add(panelQuit, BorderLayout.CENTER);

		btnQuit.addActionListener(this);

		// simple or advanced mode
		if (Config.getInstance().getIntVal("advanced", 0) == 1)
			switchMode(true);
		else
			switchMode(false);

		// help tooltips
		btnQuit.setToolTipText(HelpTexts.getInstance().getHelpText("quit"));

		// set initial parameters
		needreload = true;

		setDispTabEnabled(false);
		setNavigationEnabled(false);

	}
 
Example 18
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 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: ExportDialog.java    From GiantTrees with GNU General Public License v3.0 4 votes vote down vote up
void createGUI() {
	tabbedPane = new JTabbedPane();

	JComponent exportPanel = createExportPanel();
	tabbedPane.addTab("Export", null, exportPanel,
	                  "Export options");
	tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);

	JComponent renderPanel = createRenderPanel();
	tabbedPane.addTab("Render", null, renderPanel,
       "Render options");
	tabbedPane.setMnemonicAt(0, KeyEvent.VK_2);

	if (render) {
		tabbedPane.setSelectedIndex(1);
	}
	formatSettings(formatBox.getSelectedIndex());
	
	// buttons
	startButton = new JButton("Start");
	startButton.addActionListener(new StartButtonListener());
	
	cancelButton = new JButton("Close");
	cancelButton.addActionListener(new CancelButtonListener());
	
	JPanel buttons = new JPanel();
	buttons.add(startButton);
	buttons.add(cancelButton);
	
	JPanel panel = new JPanel();
	//panel.setLayout(new BoxLayout(panel,BoxLayout.PAGE_AXIS));
	panel.setLayout(new BorderLayout());
	panel.add(tabbedPane,BorderLayout.CENTER);
	panel.add(buttons,BorderLayout.SOUTH);
	
	// add panel to content pane
	Container contentPane = frame.getContentPane(); 
	contentPane.add(panel,BorderLayout.CENTER);
	
	// add status line
	progressbar = new Progressbar();
	progressbar.setVisible(false);
	contentPane.add(progressbar,BorderLayout.PAGE_END);
	
	frame.pack();
}