Example usage for javax.swing JTabbedPane removeAll

List of usage examples for javax.swing JTabbedPane removeAll

Introduction

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

Prototype

public void removeAll() 

Source Link

Document

Removes all the tabs and their corresponding components from the tabbedpane.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTabbedPane pane = new JTabbedPane();
    JButton component = new JButton("button");
    // Remove the last tab
    pane.remove(pane.getTabCount() - 1);

    // Remove the tab with the specified child component
    pane.remove(component);/* w w  w.j a  va  2  s .  c  o m*/

    // Remove all the tabs
    pane.removeAll();
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Tabbed Pane Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    String titles[] = { "General", "Security", "Content", "Connection", "Programs", "Advanced" };
    int mnemonic[] = { KeyEvent.VK_G, KeyEvent.VK_S, KeyEvent.VK_C, KeyEvent.VK_O, KeyEvent.VK_P,
            KeyEvent.VK_A };/*from w w w .  ja  v a 2 s  . com*/
    for (int i = 0, n = titles.length; i < n; i++) {
        add(tabbedPane, titles[i], mnemonic[i]);
    }

    tabbedPane.removeAll();
    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

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

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

    chart = model.getChart();/*from  ww  w  . ja  v a  2 s  . 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.plugins.latlon.LatLonUI.java

/**
 * Swaps the the proper form into the panel.
 * @param formInx the index of the format that is being used.
 * @param type the type of point, line or Rect being used
 *//* w  ww  . j a  va 2 s  . c om*/
protected void swapForm(final int formInx, final LatLonUIIFace.LatLonType type) {
    if (currentInx != -1 && currentInx != formInx) {
        FORMAT[] fmts = FORMAT.values();

        FORMAT fromFmt = srcFormat;
        FORMAT toFmt = fmts[formInx];

        DDDDPanel prevPanel1 = panels[(currentInx * 2)];
        DDDDPanel prevPanel2 = panels[(currentInx * 2) + 1];

        DDDDPanel nextPanel1 = panels[(formInx * 2)];
        DDDDPanel nextPanel2 = panels[(formInx * 2) + 1];

        boolean srcFormatHasChanged = prevPanel1.getDefaultFormat() != srcFormat; // same for either panel 1 or 2
        if (type == LatLonUIIFace.LatLonType.LLPoint) {
            if (prevPanel1.hasChanged()) {
                checkPanel(srcFormatHasChanged, prevPanel1, null, srcLatLon1, null, fromFmt, toFmt);

            } else if (srcLatLon1.first == null && srcLatLon1.second == null) {
                srcFormat = nextPanel1.getDefaultFormat();
            }

        } else {
            if (prevPanel1.hasChanged() && !prevPanel2.hasChanged()) {
                checkPanel(srcFormatHasChanged, prevPanel1, prevPanel2, srcLatLon1, srcLatLon2, fromFmt, toFmt);

            } else if (prevPanel2.hasChanged() && !prevPanel1.hasChanged()) {
                checkPanel(srcFormatHasChanged, prevPanel2, prevPanel1, srcLatLon2, srcLatLon1, fromFmt, toFmt);

            } else if (prevPanel1.hasChanged() && prevPanel2.hasChanged()) {
                checkPanel(srcFormatHasChanged, prevPanel1, null, srcLatLon1, null, fromFmt, toFmt);
                checkPanel(srcFormatHasChanged, prevPanel2, null, srcLatLon2, null, fromFmt, toFmt);

            } else if (srcLatLon1.first == null && srcLatLon1.second == null && srcLatLon2.first == null
                    && srcLatLon2.second == null) {
                srcFormat = nextPanel1.getDefaultFormat();
            }
        }

        nextPanel1.set(srcFormat, srcLatLon1.first, srcLatLon1.second);

        if (type == LatLonUIIFace.LatLonType.LLPoint) {
            nextPanel2.clear();

        } else {
            nextPanel2.set(srcFormat, srcLatLon2.first, srcLatLon2.second);
        }
        hasChanged = true;
        stateChanged(null);
        choosenFormat = toFmt;
    }

    // Set the radio button accordingly
    for (JToggleButton rb : selectedTypeHash.keySet()) {
        if (selectedTypeHash.get(rb).ordinal() == type.ordinal()) {
            rb.setSelected(true);
            break;
        }
    }

    JPanel panel = panels[(formInx * 2)];

    cardSubPanes[formInx].removeAll();

    if (type == LatLonUIIFace.LatLonType.LLPoint) {
        cardSubPanes[formInx].add(panel, BorderLayout.CENTER);
        panel.setBorder(panelBorder);

    } else {
        JTabbedPane tabbedPane = (JTabbedPane) latLonPanes[formInx];
        tabbedPane.removeAll();
        cardSubPanes[formInx].add(tabbedPane, BorderLayout.CENTER);
        panel.setBorder(null);

        int inx = type == LatLonUIIFace.LatLonType.LLLine ? 1 : 3;

        tabbedPane.addTab(null, pointImages[inx++], panels[(formInx * 2)]);
        tabbedPane.addTab(null, pointImages[inx], panels[(formInx * 2) + 1]);
    }

    cardPanel.validate();
    cardPanel.doLayout();
    cardPanel.repaint();

    currentInx = formInx;
}

From source file:edu.ku.brc.specify.plugins.latlon.LatLonUI.java

/**
 * Creates the UI.//w  ww. j  a  va 2  s. com
 * @param localityCEP the locality object (can be null)
 */
protected void createEditUI() {
    loadAndPushResourceBundle("specify_plugins");

    PanelBuilder builder = new PanelBuilder(new FormLayout("p", "p, 2px, p"), this);

    Color bgColor = getBackground();
    bgColor = new Color(Math.min(bgColor.getRed() + 20, 255), Math.min(bgColor.getGreen() + 20, 255),
            Math.min(bgColor.getBlue() + 20, 255));
    //System.out.println(bgColor);
    setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(bgColor),
            BorderFactory.createEmptyBorder(4, 4, 4, 4)));

    for (int i = 0; i < types.length; i++) {
        typeMapper.put(types[i], typeStrs[i]);
    }

    currentType = LatLonUIIFace.LatLonType.LLPoint;

    pointImages = new ImageIcon[pointNames.length];
    for (int i = 0; i < pointNames.length; i++) {
        pointImages[i] = IconManager.getIcon(pointNames[i], IconManager.IconSize.Std16);
    }

    String[] formatLabels = new String[formats.length];
    for (int i = 0; i < formats.length; i++) {
        formatLabels[i] = getResourceString(formats[i]);
    }
    cardPanel = new JPanel(cardLayout);
    formatSelector = createComboBox(formatLabels);
    latLonPanes = new JComponent[formatLabels.length];

    formatSelector.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            swapForm(formatSelector.getSelectedIndex(), currentType);

            cardLayout.show(cardPanel, ((JComboBox) ae.getSource()).getSelectedItem().toString());

            //stateChanged(null);
        }
    });

    Dimension preferredSize = new Dimension(0, 0);
    cardSubPanes = new JPanel[formats.length * 2];
    panels = new DDDDPanel[formats.length * 2];
    int paneInx = 0;
    for (int i = 0; i < formats.length; i++) {
        cardSubPanes[i] = new JPanel(new BorderLayout());
        try {
            String packageName = "edu.ku.brc.specify.plugins.latlon.";
            DDDDPanel latLon1 = Class.forName(packageName + formatClass[i]).asSubclass(DDDDPanel.class)
                    .newInstance();
            latLon1.setIsRequired(isRequired);
            latLon1.setViewMode(isViewMode);
            latLon1.init();
            latLon1.setChangeListener(this);

            JPanel panel1 = latLon1;
            panel1.setBorder(panelBorder);
            panels[paneInx++] = latLon1;
            latLonPanes[i] = panel1;

            DDDDPanel latlon2 = Class.forName(packageName + formatClass[i]).asSubclass(DDDDPanel.class)
                    .newInstance();
            latlon2.setIsRequired(isRequired);
            latlon2.setViewMode(isViewMode);
            latlon2.init();
            latlon2.setChangeListener(this);

            panels[paneInx++] = latlon2;

            JTabbedPane tabbedPane = new JTabbedPane(
                    UIHelper.getOSType() == UIHelper.OSTYPE.MacOSX ? SwingConstants.BOTTOM
                            : SwingConstants.RIGHT);
            tabbedPane.addTab(null, pointImages[0], panels[paneInx - 2]);
            tabbedPane.addTab(null, pointImages[0], panels[paneInx - 1]);
            latLonPanes[i] = tabbedPane;

            Dimension size = tabbedPane.getPreferredSize();
            preferredSize.width = Math.max(preferredSize.width, size.width);
            preferredSize.height = Math.max(preferredSize.height, size.height);

            tabbedPane.removeAll();
            cardSubPanes[i].add(panel1, BorderLayout.CENTER);
            cardPanel.add(formatLabels[i], cardSubPanes[i]);

            /*if (locality != null)
            {
            latLon1.set(locality.getLatitude1(), locality.getLongitude1(), locality.getLat1text(), locality.getLong1text());
            latlon2.set(locality.getLatitude2(), locality.getLongitude2(), locality.getLat2text(), locality.getLong2text());
            }*/

        } catch (Exception e) {
            e.printStackTrace();
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(LatLonUI.class, e);
        }
    }

    // Makes they are all the same size
    for (int i = 0; i < formats.length; i++) {
        cardSubPanes[i].setPreferredSize(preferredSize);
    }

    //final LatLonPanel thisPanel = this;

    PanelBuilder botBtnBar = new PanelBuilder(new FormLayout("p:g,p,10px,p,10px,p,p:g", "p"));

    ButtonGroup btnGroup = new ButtonGroup();
    botBtns = new JToggleButton[typeNames.length];

    if (UIHelper.isMacOS()) {
        /*for (int i=0;i<botBtns.length;i++)
        {
        ImageIcon selIcon   = IconManager.getIcon(typeNames[i]+"Sel", IconManager.IconSize.Std16);
        ImageIcon unselIcon = IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16);
                
        MacIconRadioButton rb = new MacIconRadioButton(selIcon, unselIcon);
        botBtns[i] = rb;
        rb.setBorder(new MacBtnBorder());
                
        Dimension size = rb.getPreferredSize();
        int max = Math.max(size.width, size.height);
        size.setSize(max, max);
        rb.setPreferredSize(size);
        }*/

        BorderedRadioButton.setSelectedBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
        BorderedRadioButton.setUnselectedBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
        for (int i = 0; i < botBtns.length; i++) {
            BorderedRadioButton rb = new BorderedRadioButton(
                    IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16));
            botBtns[i] = rb;
            rb.makeSquare();
            rb.setBorder(new MacBtnBorder());
        }
    } else {
        BorderedRadioButton.setSelectedBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
        BorderedRadioButton.setUnselectedBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
        for (int i = 0; i < botBtns.length; i++) {
            BorderedRadioButton rb = new BorderedRadioButton(
                    IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16));
            botBtns[i] = rb;
            rb.makeSquare();
        }
    }

    for (int i = 0; i < botBtns.length; i++) {
        botBtns[i].setToolTipText(typeToolTips[i]);
        botBtnBar.add(botBtns[i], cc.xy((i * 2) + 2, 1));
        btnGroup.add(botBtns[i]);
        selectedTypeHash.put(botBtns[i], types[i]);

        botBtns[i].addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ce) {
                stateChanged(null);
                currentType = selectedTypeHash.get(ce.getSource());
                swapForm(formatSelector.getSelectedIndex(), currentType);
            }
        });
    }
    botBtns[0].setSelected(true);

    if (isViewMode) {
        typeLabel = createLabel(" ");
    }

    ActionListener infoAL = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doPrefs();
        }
    };

    JButton infoBtn = UIHelper.createIconBtn("Preferences", IconManager.IconSize.Std16,
            getResourceString("PREFERENCES"), true, infoAL);
    infoBtn.setEnabled(true);

    PanelBuilder topPane = new PanelBuilder(
            new FormLayout("l:p, c:p:g" + (isViewMode ? "" : ",4px,p,8px"), "p"));
    topPane.add(formatSelector, cc.xy(1, 1));
    topPane.add(isViewMode ? typeLabel : botBtnBar.getPanel(), cc.xy(2, 1));
    if (!isViewMode)
        topPane.add(infoBtn, cc.xy(4, 1));

    builder.add(topPane.getPanel(), cc.xy(1, 1));
    builder.add(cardPanel, cc.xy(1, 3));

    prefsPanel = new PrefsPanel(false);
    prefsPanel.add(getResourceString("LatLonUI.LL_SEP"));
    prefsPanel.add(CompType.eCheckbox, getResourceString("LatLonUI.LATDEF_DIR"), LAT_PREF, Boolean.class, true);
    prefsPanel.add(CompType.eCheckbox, getResourceString("LatLonUI.LONDEF_DIR"), LON_PREF, Boolean.class, true);
    prefsPanel.add(CompType.eComboBox, getResourceString("LatLonUI.DEF_TYP"), TYP_PREF, Integer.class,
            typeNamesLabels, 0);
    prefsPanel.add(CompType.eComboBox, getResourceString("LatLonUI.DEF_FMT"), FMT_PREF, Integer.class,
            formatLabels, 0);
    prefsPanel.createForm(null, null);

    popResourceBundle();
}