Example usage for javax.swing JTabbedPane getTabCount

List of usage examples for javax.swing JTabbedPane getTabCount

Introduction

In this page you can find the example usage for javax.swing JTabbedPane getTabCount.

Prototype

@BeanProperty(bound = false)
public int getTabCount() 

Source Link

Document

Returns the number of tabs in this tabbedpane.

Usage

From source file:dr.app.bss.Utils.java

public static int getTabbedPaneComponentIndex(JTabbedPane tabbedPane, String title) {

    int index = -Integer.MAX_VALUE;

    int count = tabbedPane.getTabCount();
    for (int i = 0; i < count; i++) {
        if (tabbedPane.getTitleAt(i).toString().equalsIgnoreCase(title)) {
            index = i;/*  ww  w  .  j a va2s  .c o m*/
            break;
        } // END: title check

    } // END: i loop

    return index;
}

From source file:main.UIController.java

public void initializeWindow(boolean useCacheSunset, int selectedTab) {
    this.initializeWindow(useCacheSunset);
    JTabbedPane tabbedPane = UI.getInstance().getTabbedPane();
    if (selectedTab >= 0 && selectedTab < tabbedPane.getTabCount()) {
        tabbedPane.setSelectedIndex(selectedTab);
    }//w ww .  jav  a  2s.  com
}

From source file:org.nuclos.client.layout.wysiwyg.component.properties.PropertyChartPropertyGeneralStep.java

@Override
public void prepare() {
    super.prepare();

    chart = model.getChart();//  w  ww  .j  av a 2s.  c o  m
    chartEditor = ChartEditorManager.getChartEditor(chart);

    try {
        jTabbedPanels = getChartFunction().getCustomPlotEditorPanels(model.getWYSIWYGChart().getChart());
        if (jTabbedPanels.length > 0) {
            JPanel editor = (JPanel) UIUtils.findFirstJComponent((JPanel) chartEditor,
                    (Class) Class.forName("org.jfree.chart.editor.DefaultPlotEditor"));
            JTabbedPane tab = (JTabbedPane) UIUtils.findFirstJComponent(editor, JTabbedPane.class);

            if (getChartFunction().isCombinedChart())
                tab.removeAll();

            for (int i = 0; i < jTabbedPanels.length; i++) {
                JTabbedPanel jTabbedPanel = jTabbedPanels[i];
                if (getChartFunction().isCombinedChart())
                    tab.insertTab(jTabbedPanel.getTitle(), null, jTabbedPanel, null, i);
                else
                    tab.insertTab(jTabbedPanel.getTitle(), null, jTabbedPanel, null, tab.getTabCount());
            }
            tab.setSelectedIndex(0);
        }
    } catch (Exception e) {
        e.printStackTrace();
        // ignore.
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.lm.LifeMapperPane.java

/**
 * @return/* w w w  .  j  a va  2s . c  om*/
 */
private int getCurrentSizeSquare() {
    int maxHeight = MAP_HEIGHT;
    int maxWidth = MAP_WIDTH;
    if (SubPaneMgr.getInstance() instanceof JTabbedPane) {
        Dimension size;
        JTabbedPane tbPane = (JTabbedPane) SubPaneMgr.getInstance();
        if (tbPane.getTabCount() > 0) {
            size = tbPane.getComponentAt(0).getSize();
        } else {
            size = tbPane.getSize();
            size.height -= 30;
        }
        int lblHeight = (UIHelper.createLabel(" ").getPreferredSize().height) * 5;
        maxHeight = size.height - lblHeight - IMG_HEIGHT - 30;
        maxWidth = size.width - 20;
    }
    return Math.min(maxHeight, maxWidth);
}

From source file:it.iit.genomics.cru.igb.bundles.mi.business.MIWorker.java

public void addResultTab(String summary, List<MIResult> results, String label, MIQuery query) {

    JTabbedPane resultsTabbedPan = MIView.getInstance().getResultsTabbedPan();

    MIResultPanel resultPane = new MIResultPanel(service, summary, results, label, query);

    addClosableTab(resultsTabbedPan, resultPane, label);
    // select the new (last) tab
    resultsTabbedPan.setSelectedIndex(resultsTabbedPan.getTabCount() - 1);

}

From source file:gui.LauncherFrame.java

/**
 * removes a tab that begins with the specified name.
 * //from  w  ww . j a v a2 s . c  o m
 * @param tabbedPane - the tabbed pane to remove an entry from
 * @param name - the name (or begining of the name) of the tab
 * 
 * @return 1 if tab removed, 0 if not
 */
private int removeTextTab(javax.swing.JTabbedPane tabbedPane, String name) {
    int count = tabbedPane.getTabCount();
    for (int ix = 0; ix < count; ix++) {
        String tabname = tabbedPane.getTitleAt(ix);
        if (tabname.startsWith(name)) {
            tabbedPane.removeTabAt(ix);
            debug.print(DebugMessage.StatusType.Info, "Removed tab: " + tabname);
            return 1;
        }
    }

    return 0;
}

From source file:org.nuclos.client.layout.wysiwyg.component.properties.PropertyChartPropertyDomainStep.java

@Override
public void prepare() {
    super.prepare();

    chart = model.getChart();/*from  ww  w  .j  a v  a2  s. co  m*/
    wysiwygChart = model.getWYSIWYGChart();

    String sPrefix = getChartProperty(Chart.PROPERTY_COMBINED_PREFIXES);
    combinedPrefixes = (sPrefix == null) ? new StringBuffer("") : new StringBuffer(sPrefix);

    panel = new JPanel();
    panel.setLayout(new BorderLayout());

    final ChartFunction chartFunction = getChartFunction();

    if (!chartFunction.isCombinedChart()) {
        panel.add(getPanelComponent(chartFunction, ""), BorderLayout.CENTER);
    } else {
        JPanel editorType = new JPanel();
        editorType.setLayout(new GridBagLayout());
        JLabel propTypeValue = new JLabel(
                //SpringLocaleDelegate.getInstance().getMessage("wysiwyg.chart.wizard.domain.value",
                "Diagramm hinzufgen:"/*)*/);
        editorType.add(propTypeValue, new GridBagConstraints(0, 0, 0, 1, 1D, 1D, GridBagConstraints.NORTHWEST,
                GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
        final JComboBox propTypeComponent = new JComboBox(chartFunction.getCombinedChartFunctions());
        editorType.add(propTypeComponent, new GridBagConstraints(0, 1, 1, 1, 1D, 1D,
                GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 15, 0), 0, 0));

        final JTabbedPane tabbedPane = new JTabbedPane();

        JButton removeButton = new JButton(iconRemove);
        removeButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (tabbedPane.getSelectedIndex() != -1) {
                    PanelComponent panelComponent = (PanelComponent) tabbedPane.getSelectedComponent();
                    combinedPrefixes = new StringBuffer(
                            combinedPrefixes.toString().replaceAll(panelComponent.prefix, ""));
                    tabbedPane.remove(panelComponent);
                }
            }
        });
        editorType.add(removeButton, new GridBagConstraints(1, 1, 1, 1, 1D, 1D, GridBagConstraints.NORTHEAST,
                GridBagConstraints.NONE, new Insets(5, 0, 0, 0), 0, 0));
        JButton addButton = new JButton(iconAdd);
        addButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ChartFunction cFunction = (ChartFunction) propTypeComponent.getSelectedItem();
                String prefix = cFunction.name() + "." + (Math.random() + "").replaceAll("\\.", "") + ":";

                combinedPrefixes.append(prefix);
                tabbedPane.add(cFunction.name(), getPanelComponent(cFunction, prefix));
                tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
            }
        });
        editorType.add(addButton, new GridBagConstraints(2, 1, 1, 1, 1D, 1D, GridBagConstraints.NORTHWEST,
                GridBagConstraints.NONE, new Insets(5, 0, 0, 0), 0, 0));

        String[] prefixes = combinedPrefixes.toString().split(":");
        for (String prefix : prefixes) {
            if (prefix.length() > 0) {
                try {
                    ChartFunction cFunction = ChartFunction.valueOf(prefix.split("\\.")[0]);
                    tabbedPane.add(cFunction.name(), getPanelComponent(cFunction, prefix + ":"));
                } catch (Exception e) {
                    // ignore.
                }
            }
        }
        panel.add(editorType, BorderLayout.NORTH);
        panel.add(tabbedPane, BorderLayout.CENTER);
    }
}

From source file:course_generator.frmMain.java

/**
 * Add a tab to JTabbedPane. The icon is at the left of the text and there
 * some space between the icon and the label
 * /*from   w w w .j  ava 2s  .  co m*/
 * @param tabbedPane
 *            JTabbedPane where we want to add the tab
 * @param tab
 *            Tab to add
 * @param title
 *            Title of the tab
 * @param icon
 *            Icon of the tab
 */
private void addTab(JTabbedPane tabbedPane, Component tab, String title, Icon icon) {
    tabbedPane.add(tab);

    // Create bespoke component for rendering the tab.
    javax.swing.JLabel lbl = new javax.swing.JLabel(title);
    lbl.setIcon(icon);

    // Add some spacing between text and icon, and position text to the RHS.
    lbl.setIconTextGap(5);
    lbl.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

    tabbedPane.setTabComponentAt(tabbedPane.getTabCount() - 1, lbl);
}

From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java

private void selectTabPane(CollectableGenericObjectWithDependants clct) {
    // select tab in state
    //Integer iState = (Integer)clct.getField(NuclosEOField.STATENUMBER.getMetaData().getField()).getValueId();
    DynamicAttributeVO vo = clct.getGenericObjectCVO()
            .getAttribute(NuclosEOField.STATENUMBER.getMetaData().getId().intValue());
    if (vo == null)
        return;/*from  w  w  w .  j a  va  2 s.  c o m*/
    Integer iState = (Integer) vo.getValue();

    String strTabName = getPreferences().get(TABSELECTED, "");
    for (StateVO voState : StateDelegate.getInstance().getStatesByModule(getModuleId()))
        if (voState.getNumeral().equals(iState)) {
            if (voState.getTabbedPaneName() != null)
                strTabName = voState.getTabbedPaneName();
            break;
        }

    JComponent jcomp = layoutrootDetails.getRootComponent();
    List<JTabbedPane> lst = new ArrayList<JTabbedPane>();

    searchTabbedPanes(jcomp, lst);

    for (JTabbedPane tabPane : lst)
        for (int i = 0; i < tabPane.getTabCount(); i++)
            if (org.apache.commons.lang.StringUtils.equals(tabPane.getComponentAt(i).getName(), strTabName)
                    || org.apache.commons.lang.StringUtils.equals(tabPane.getTitleAt(i), strTabName)) {
                tabPane.setSelectedIndex(i);
                break;
            }

    adjustTabbedPanes(lst);
}

From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java

private void adjustTabbedPanes(List<JTabbedPane> lst) {
    for (JTabbedPane tabPane : lst) {
        List<Component> lstTabToRemove = new ArrayList<Component>(tabPane.getTabCount());
        for (int i = 0; i < tabPane.getTabCount(); i++) {
            Component c = tabPane.getComponentAt(i);
            if (c instanceof JComponent) {
                List<JComponent> lstComponents = new ArrayList<JComponent>();
                collectComponents((JComponent) c, lstComponents);
                if (lstComponents.size() == 0) {
                    tabPane.setEnabledAt(i, false);
                    lstTabToRemove.add(c);
                    break;
                }// w  w  w. java 2 s .  co m

                boolean blnVisible = false;
                for (JComponent jc : lstComponents) {
                    if (jc instanceof LabeledComponent) {
                        LabeledComponent lc = (LabeledComponent) jc;
                        blnVisible = lc.isVisible();
                    } else if (jc instanceof JPanel)
                        blnVisible = false;
                    else
                        blnVisible = jc.isVisible();
                    if (blnVisible)
                        break;
                }

                tabPane.setEnabledAt(i, !blnVisible ? blnVisible : blnVisible && tabPane.isEnabledAt(i));
                if (!blnVisible)
                    lstTabToRemove.add(c);
            }
        }
        for (Component c : lstTabToRemove) {
            tabPane.remove(c);
        }
    }
}