Example usage for javax.swing JTabbedPane remove

List of usage examples for javax.swing JTabbedPane remove

Introduction

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

Prototype

public void remove(int index) 

Source Link

Document

Removes the tab and component which corresponds to the specified index.

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);//  ww  w.ja v a  2s . c o m

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

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTabbedPane pane = new JTabbedPane();
    int src = pane.getTabCount() - 1;
    int dst = 0;//  w  ww  .  j av a 2s .co  m

    Component comp = pane.getComponentAt(src);
    String label = pane.getTitleAt(src);
    Icon icon = pane.getIconAt(src);
    Icon iconDis = pane.getDisabledIconAt(src);
    String tooltip = pane.getToolTipTextAt(src);
    boolean enabled = pane.isEnabledAt(src);
    int keycode = pane.getMnemonicAt(src);
    int mnemonicLoc = pane.getDisplayedMnemonicIndexAt(src);
    Color fg = pane.getForegroundAt(src);
    Color bg = pane.getBackgroundAt(src);

    pane.remove(src);

    pane.insertTab(label, icon, comp, tooltip, dst);

    pane.setDisabledIconAt(dst, iconDis);
    pane.setEnabledAt(dst, enabled);
    pane.setMnemonicAt(dst, keycode);
    pane.setDisplayedMnemonicIndexAt(dst, mnemonicLoc);
    pane.setForegroundAt(dst, fg);
    pane.setBackgroundAt(dst, bg);
}

From source file:org.chocosolver.gui.panels.APanel.java

public void unplug(JTabbedPane tabbedpanel) {
    tabbedpanel.remove(this);
    activate = false;
}

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

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

    chart = model.getChart();/*  ww w. j  ava  2s  .  c om*/
    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:de.bfs.radon.omsimulation.gui.OMPanelResults.java

/**
 * Creates a panel displaying the distribution chart of certain selected
 * statistical values./*from   w  ww.j  ava2s.  co  m*/
 * 
 * @param title
 *          The headline of the chart. Will be hidden if set to null.
 * @param statistics
 *          The selected statistics of a campaign containing all needed
 *          values.
 * @param roomType
 *          The room type to determine the colour of the chart.
 * @param preview
 *          Will hide annotations, labels and headlines if set true.
 * @param fullscreen
 *          Will correctly adjust the preferred size to screen resolution if
 *          true.
 * @param mouseEvent
 *          Will enable mouseClickedEvent if set true. Use with care, and only
 *          inside the results panel. Set to false if you are unsure what you
 *          are doing.
 * @return A chart displaying the distribution of certain selected statistical
 *         values.
 */
public JPanel createDistributionPanel(String title, DescriptiveStatistics statistics, OMRoomType roomType,
        boolean preview, boolean fullscreen, boolean mouseEvent) {
    JFreeChart chart = OMCharts.createDistributionChart(title, statistics, roomType, preview);
    ChartPanel chartPanel = new ChartPanel(chart);
    Dimension dim;
    if (fullscreen) {
        dim = Toolkit.getDefaultToolkit().getScreenSize();
    } else {
        dim = new Dimension(730, 347);
    }
    chartPanel.setPreferredSize(dim);
    if (mouseEvent) {
        chartPanel.addChartMouseListener(new ChartMouseListener() {
            @Override
            public void chartMouseClicked(ChartMouseEvent e) {
                OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                OMCampaign[] campaigns = simulation.getCampaigns();
                try {
                    XYItemEntity entity = (XYItemEntity) e.getEntity();
                    XYDataset dataset = entity.getDataset();
                    int item = entity.getItem();
                    double x = dataset.getXValue(0, item);
                    double comparable = 0.0;
                    OMCampaign result = null;
                    OMStatistics selectedType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                    for (int i = 0; i < campaigns.length; i++) {
                        switch (selectedType) {
                        case RoomArithmeticMeans:
                            comparable = campaigns[i].getRoomAverage();
                            break;
                        case RoomGeometricMeans:
                            comparable = campaigns[i].getRoomLogAverage();
                            break;
                        case RoomMedianQ50:
                            comparable = campaigns[i].getRoomMedian();
                            break;
                        case RoomMaxima:
                            comparable = campaigns[i].getRoomMaximum();
                            break;
                        case CellarArithmeticMeans:
                            comparable = campaigns[i].getCellarAverage();
                            break;
                        case CellarGeometricMeans:
                            comparable = campaigns[i].getCellarLogAverage();
                            break;
                        case CellarMedianQ50:
                            comparable = campaigns[i].getCellarMedian();
                            break;
                        case CellarMaxima:
                            comparable = campaigns[i].getCellarMaximum();
                            break;
                        default:
                            comparable = campaigns[i].getRoomAverage();
                            break;
                        }
                        if (comparable == x) {
                            result = campaigns[i];
                        }
                    }
                    if (result != null) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException ie) {
                            ie.printStackTrace();
                        }
                        JTabbedPane tab = (JTabbedPane) getParent();
                        tab.remove(tab.getComponentAt(4));
                        JPanel jpanelTesting = new OMPanelTesting(simulation, result);
                        tab.add(jpanelTesting, "Analyse", 4);
                        tab.updateUI();
                        tab.setSelectedIndex(4);
                    }
                } catch (Exception x) {
                    x.printStackTrace();
                }
            }

            @Override
            public void chartMouseMoved(ChartMouseEvent ignore) {
            }
        });
    }
    JPanel distPanel = (JPanel) chartPanel;
    return distPanel;
}

From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java

/**
 * Removes the given Job Tab Pane//from w ww. ja  v a 2  s.c o m
 * @param jobId JobId of pane
 */
protected void removeJobTab(String jobId) {

    // Detach Tab
    JTabbedPane tabs = getUIElement("tabs");
    tabs.remove(getUIElement("jobs." + jobId));
    tabs.revalidate();

    // Remove UI Elements
    removeUIElement("jobs." + jobId + ".progress");
    removeUIElement("jobs." + jobId + ".terminate");
    removeUIElement("jobs." + jobId + ".closetab");
    removeUIElement("jobs." + jobId + ".job.name");
    removeUIElement("jobs." + jobId + ".job.type");
    removeUIElement("jobs." + jobId + ".job.class");
    removeUIElement("jobs." + jobId + ".execution.status");
    removeUIElement("jobs." + jobId + ".execution.percentage");
    removeUIElement("jobs." + jobId + ".execution.starttime");
    removeUIElement("jobs." + jobId + ".execution.elapsedtime");
    removeUIElement("jobs." + jobId + ".execution.tasks");
    removeUIElement("jobs." + jobId + ".execution.results");
    removeUIElement("jobs." + jobId + ".execution.remaining");
    removeUIElement("jobs." + jobId + ".execution.failed");
    removeUIElement("jobs." + jobId + ".owner.hostname");
    removeUIElement("jobs." + jobId + ".owner.hostip");
    removeUIElement("jobs." + jobId + ".owner.id");
    removeUIElement("jobs." + jobId);
}

From source file:fur.shadowdrake.minecraft.InstallPanel.java

public boolean changeJvmParameters() {
    if (packList.isEmpty()) {
        log.println("No packs installed.");
        return false;
    }//from  w ww  . j  ava2  s.c o m

    profileChooser.setModel(new DefaultComboBoxModel<>(profiles.profiles.keySet().toArray(new String[0])));
    profileChooserActionPerformed(null);
    parentFrame.setProceedListener((ActionEvent e) -> {
        JTabbedPane tabPane = (JTabbedPane) parameterPanel.getParent();
        tabPane.remove(parameterPanel);
        commitJvmParameters();
        parentFrame.state &= ~1;
        log.setStatusText("Ok");
    });
    parentFrame.setAbortListener((ActionEvent e) -> {
        JTabbedPane tabPane = (JTabbedPane) parameterPanel.getParent();
        tabPane.remove(parameterPanel);
        parentFrame.state &= ~1;
        log.setStatusText("Ok");
    });
    return true;
}

From source file:fur.shadowdrake.minecraft.InstallPanel.java

private void addonsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addonsActionPerformed
    addonsPanel = new AddonsPanel(
            availablePacks.get(modpackChooser.getSelectedIndex()).addons.toArray(new Addon[0]));
    JTabbedPane tabPane;
    tabPane = (JTabbedPane) getParent();
    tabPane.remove(this);
    tabPane.add("Addons", addonsPanel);
    tabPane.setSelectedComponent(addonsPanel);
    addonsOpenedOnce = true;/* ww  w  .  j a  v a 2 s. co  m*/
    parentFrame.setAbortListener((ActionEvent e) -> {
        tabPane.remove(addonsPanel);
        tabPane.add("Install", this);
        tabPane.setSelectedComponent(this);
    });
    parentFrame.setProceedListener((ActionEvent e) -> {
        boolean s[];
        tabPane.remove(addonsPanel);
        tabPane.add("Install", this);
        tabPane.setSelectedComponent(this);
        s = addonsPanel.getSelected();
        for (int n = 0; n < s.length; n++) {
            availablePacks.get(modpackChooser.getSelectedIndex()).addons.get(n).install = s[n];
        }
    });
}

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

/**
 * Adds a component to a JTabbedPane with a little close tab" button on the
 * right side of the tab./*from  w  w w.  j  a  v a2s . co m*/
 *
 * @param tabbedPane
 *            the JTabbedPane
 * @param c
 *            any JComponent
 * @param title
 *            the title for the tab
 */
public static void addClosableTab(final JTabbedPane tabbedPane, final JComponent c, final String title) {
    // Add the tab to the pane without any label
    tabbedPane.addTab(null, c);
    int pos = tabbedPane.indexOfComponent(c);

    // Create a FlowLayout that will space things 5px apart
    FlowLayout f = new FlowLayout(FlowLayout.CENTER, 5, 0);

    // Make a small JPanel with the layout and make it non-opaque
    JPanel pnlTab = new JPanel(f);
    pnlTab.setOpaque(false);

    // Add a JLabel with title and the left-side tab icon
    JLabel lblTitle = new JLabel(title);

    // Create a JButton for the close tab button
    JButton btnClose = new JButton("x");
    // btnClose.setOpaque(false);
    int size = 17;
    btnClose.setPreferredSize(new Dimension(size, size));
    btnClose.setToolTipText("close this tab");
    // Make the button looks the same for all Laf's
    btnClose.setUI(new BasicButtonUI());
    // Make it transparent
    btnClose.setContentAreaFilled(false);
    // No need to be focusable
    btnClose.setFocusable(false);
    btnClose.setBorder(BorderFactory.createEtchedBorder());
    btnClose.setBorderPainted(false);
    // Making nice rollover effect
    // we use the same listener for all buttons
    btnClose.setRolloverEnabled(true);
    // Close the proper tab by clicking the button

    // Configure icon and rollover icon for button
    btnClose.setRolloverEnabled(true);

    // Set border null so the button doesnt make the tab too big
    btnClose.setBorder(null);
    // Make sure the button cant get focus, otherwise it looks funny
    btnClose.setFocusable(false);

    // Put the panel together
    pnlTab.add(lblTitle);
    pnlTab.add(btnClose);

    // Add a thin border to keep the image below the top edge of the tab
    // when the tab is selected
    pnlTab.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
    // Now assign the component for the tab
    tabbedPane.setTabComponentAt(pos, pnlTab);

    // Add the listener that removes the tab
    ActionListener listener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showConfirmDialog(new JFrame(),
                    "Are you sure you want to remove this tab? All results will be lost!", "Remove tab",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                tabbedPane.remove(c);
            }
        }
    };
    btnClose.addActionListener(listener);

    // Optionally bring the new tab to the front
    tabbedPane.setSelectedComponent(c);

}

From source file:fur.shadowdrake.minecraft.InstallPanel.java

public void begin(boolean first) {
    workingDir = dirBox.getText();/* w  w  w  .j a va 2 s.co m*/
    workingPack = (String) modpackChooser.getSelectedItem();
    parentFrame.dropAllProceedListeners();
    new Thread(() -> {
        try {
            JTabbedPane tabPane;
            tabPane = (JTabbedPane) getParent();

            if (force.isSelected()) {
                log.println("Cleaning up.");
                cleanUp(new File(workingDir));
                Manifest mf = manifest.get(workingPack);
                if (mf != null) {
                    mf.clear();
                }
            }

            Pack detected = detectPack(new File(workingDir));
            if ((detected == null) && checkDir(new File(workingDir), 2)) {
                try {
                    EventQueue.invokeAndWait(() -> {
                        JOptionPane.showMessageDialog(parentFrame,
                                "This directory contains an unknown modpack.\nChoose another directory or force reinstall.");
                    });
                } catch (InterruptedException | InvocationTargetException ex) {
                }
                completedListener.actionPerformed(new ActionEvent(this, 2, "Install"));
            } else if (detected == null) {
                try {
                    EventQueue.invokeAndWait(() -> {
                        tabPane.remove(this);
                    });
                } catch (InterruptedException | InvocationTargetException ex) {
                }

                if (first && !addonsOpenedOnce) {
                    addonsPanel = new AddonsPanel(
                            availablePacks.get(modpackChooser.getSelectedIndex()).addons.toArray(new Addon[0]));
                    tabPane.add("Addons", addonsPanel);
                    tabPane.setSelectedComponent(addonsPanel);
                    addonsOpenedOnce = true;
                    parentFrame.setAbortListener((ActionEvent e) -> {
                        tabPane.remove(addonsPanel);
                        tabPane.add("Install", this);
                        tabPane.setSelectedComponent(this);
                        parentFrame.setProceedListener((ActionEvent ev) -> {
                            begin(false);
                        });
                        parentFrame.setAbortListener((ActionEvent ev) -> {
                            tabPane.remove(this);
                            parentFrame.state = 0;
                            parentFrame.dropAllAbortListeners();
                            parentFrame.dropAllProceedListeners();
                        });
                    });
                    parentFrame.setProceedListener((ActionEvent e) -> {
                        tabPane.remove(addonsPanel);
                        boolean s[];
                        s = addonsPanel.getSelected();
                        for (int n = 0; n < s.length; n++) {
                            availablePacks.get(modpackChooser.getSelectedIndex()).addons.get(n).install = s[n];
                        }
                        begin(false);
                    });
                    return;
                }

                if (downloadPack() && downloadAddons() && doPostDownload()) {
                    log.println("Installation completed successful.");
                    log.setStatusText("Ok");
                    completedListener.actionPerformed(new ActionEvent(this, 1, "Install"));
                } else {
                    log.println("Installation completed with errors.");
                    log.setStatusText("Error");
                    EventQueue.invokeLater(() -> {
                        JOptionPane.showMessageDialog(parentFrame, "Installation failed");
                    });
                    completedListener.actionPerformed(new ActionEvent(this, 0, "Install"));
                }
            } else if (detected.name.equals(modpackChooser.getSelectedItem())) {
                if (!isInstalled(detected)) {
                    try {
                        Gson gson = new GsonBuilder().create();
                        tabPane.remove(this);
                        packList.add(detected);

                        String latestVersion = ftpClient.getLatestVersion(detected.name);
                        if (!latestVersion.equals(detected.version)) {
                            updatePack(detected);
                        }

                        try (FileWriter fw = new FileWriter(
                                new File(config.getInstallDir(), "modpacks.json"))) {
                            gson.toJson(packList, fw);
                        }
                        log.println("Installation completed successful.");
                        completedListener.actionPerformed(new ActionEvent(this, 1, "Install"));
                    } catch (IOException ex1) {
                        log.println("Installation failed.");
                        Logger.getLogger(InstallPanel.class.getName()).log(Level.SEVERE, null, ex1);
                    }
                } else {
                    try {
                        EventQueue.invokeAndWait(() -> {
                            tabPane.remove(this);
                        });
                    } catch (InterruptedException | InvocationTargetException ex) {
                    }
                    if (downloadAddons()) {
                        log.println("Installation completed successful.");
                        log.setStatusText("Ok");
                        log.reset();
                        completedListener.actionPerformed(new ActionEvent(this, 1, "Install"));
                    } else {
                        log.println("Installation failed.");
                        EventQueue.invokeLater(() -> {
                            JOptionPane.showMessageDialog(parentFrame, "Installation failed");
                        });
                    }
                }
            } else {
                try {
                    EventQueue.invokeAndWait(() -> {
                        JOptionPane.showMessageDialog(parentFrame, "This directory contains modpack "
                                + detected.name + ".\nSelect the correct pack or force reinstall.");
                    });
                } catch (InterruptedException | InvocationTargetException ex) {
                }
                completedListener.actionPerformed(new ActionEvent(this, 2, "Install"));
            }
            writeFiles();
        } catch (NetworkException ex) {
            Logger.getLogger(InstallPanel.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(parentFrame, ex.getMessage(), "Network error",
                    JOptionPane.ERROR_MESSAGE);
            ftpClient.close();
            log.println(
                    "Timeout. Previous command wasn't received by the server. This is a network error. Please try again later.");
            log.setStatusText("Error");
        }
    }, "Installer").start();
}