Example usage for javax.swing JTabbedPane insertTab

List of usage examples for javax.swing JTabbedPane insertTab

Introduction

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

Prototype

public void insertTab(String title, Icon icon, Component component, String tip, int index) 

Source Link

Document

Inserts a new tab for the given component, at the given index, represented by the given title and/or icon, either of which may be null .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTabbedPane pane = new JTabbedPane();
    JButton component = new JButton("button");

    int index = 1;
    pane.insertTab("label", new ImageIcon("icon.png"), component, "tooltip", index);

}

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;//from  w ww .j a  va  2 s .c  om

    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:Main.java

public static void main(String[] args) {
    JTabbedPane tab = new JTabbedPane();
    tab.addTab("A", new JPanel());
    tab.addTab("+", new JPanel());
    tab.getModel().addChangeListener(new ChangeListener() {
        private int lastSelected;
        private boolean ignore = false;

        @Override/*w ww.  j a  v a 2s.co m*/
        public void stateChanged(ChangeEvent e) {
            if (!ignore) {
                ignore = true;
                try {
                    int selected = tab.getSelectedIndex();
                    String title = tab.getTitleAt(selected);
                    if ("+".equals(title)) {
                        JPanel pane = new JPanel();
                        tab.insertTab("Tab" + (tab.getTabCount() - 1), null, pane, null, lastSelected + 1);
                        tab.setSelectedComponent(pane);
                    } else {
                        lastSelected = selected;
                    }
                } finally {
                    ignore = false;
                }
            }
        }
    });
    final JButton btn = new JButton("Add");
    btn.addActionListener(e -> System.out.println(tab.getTabCount()));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(tab);
    frame.add(btn, BorderLayout.SOUTH);
    frame.pack();
    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 .  j  a v a 2s .co 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:org.zaproxy.zap.extension.customFire.ScanProgressDialog.java

/**
 * //from   ww  w  .  j a  v a2 s . com
 */
private void initialize() {
    this.setSize(new Dimension(580, 504));

    if (site != null) {

        this.setTitle("Scann Progress");

    }

    JTabbedPane tabbedPane = new JTabbedPane();
    JPanel tab1 = new JPanel();
    tab1.setLayout(new GridBagLayout());

    JPanel hostPanel = new JPanel();

    hostPanel.setLayout(new GridBagLayout());

    hostPanel.add(new JLabel("Host:"), LayoutHelper.getGBC(0, 0, 1, 0.4D));

    hostPanel.add(getHostSelect(), LayoutHelper.getGBC(1, 0, 1, 0.6D));

    tab1.add(hostPanel, LayoutHelper.getGBC(0, 0, 3, 1.0D, 0.0D));

    tab1.add(getJScrollPane(), LayoutHelper.getGBC(0, 1, 3, 1.0D, 1.0D));//*

    tab1.add(new JLabel(), LayoutHelper.getGBC(0, 1, 1, 1.0D, 0.0D)); // spacer
    tab1.add(getCloseButton(), LayoutHelper.getGBC(1, 2, 1, 0.0D, 0.0D));

    tab1.add(new JLabel(), LayoutHelper.getGBC(2, 1, 1, 1.0D, 0.0D)); // spacer

    tabbedPane.insertTab("Progress", null, tab1, null, 0);
    this.add(tabbedPane);

    int mins = extension.getScannerParam().getMaxChartTimeInMins();
    if (mins > 0) {
        // Treat zero mins as disabled

        JPanel tab2 = new JPanel();

        tab2.setLayout(new GridBagLayout());

        this.seriesTotal = new TimeSeries("TotalResponses"); // Name not shown, so no need to i18n
        final TimeSeriesCollection dataset = new TimeSeriesCollection(this.seriesTotal);

        this.series100 = new TimeSeries("1xx");
        this.series200 = new TimeSeries("2xx");
        this.series300 = new TimeSeries("3xx");
        this.series400 = new TimeSeries("4xx");
        this.series500 = new TimeSeries("5xx");

        this.seriesTotal.setMaximumItemAge(mins * 60);
        this.series100.setMaximumItemAge(mins * 60);
        this.series200.setMaximumItemAge(mins * 60);
        this.series300.setMaximumItemAge(mins * 60);
        this.series400.setMaximumItemAge(mins * 60);
        this.series500.setMaximumItemAge(mins * 60);

        dataset.addSeries(series100);
        dataset.addSeries(series200);
        dataset.addSeries(series300);
        dataset.addSeries(series400);
        dataset.addSeries(series500);

        chart = createChart(dataset);//*

        // Set up some vaguesly sensible colours
        chart.getXYPlot().getRenderer(0).setSeriesPaint(0, Color.BLACK); // Totals
        chart.getXYPlot().getRenderer(0).setSeriesPaint(1, Color.ORANGE); // 100: Info
        chart.getXYPlot().getRenderer(0).setSeriesPaint(2, Color.GREEN); // 200: OK
        chart.getXYPlot().getRenderer(0).setSeriesPaint(3, Color.BLUE); // 300: Info
        chart.getXYPlot().getRenderer(0).setSeriesPaint(4, Color.YELLOW); // 400: Bad req
        chart.getXYPlot().getRenderer(0).setSeriesPaint(5, Color.RED); // 500: Internal error

        chart.getXYPlot().getRenderer(0).setSeriesStroke(0, new BasicStroke(5.0f)); // Totals
        chart.getXYPlot().getRenderer(0).setSeriesStroke(0, new BasicStroke(3.0f)); // 100: Info
        chart.getXYPlot().getRenderer(0).setSeriesStroke(0, new BasicStroke(3.0f)); // 200: OK
        chart.getXYPlot().getRenderer(0).setSeriesStroke(0, new BasicStroke(3.0f)); // 300: Info
        chart.getXYPlot().getRenderer(0).setSeriesStroke(0, new BasicStroke(3.0f)); // 400: Bad req
        chart.getXYPlot().getRenderer(0).setSeriesStroke(0, new BasicStroke(3.0f)); // 500: Internal error

        final ChartPanel chartPanel = new ChartPanel(chart);

        tab2.add(chartPanel, LayoutHelper.getGBC(0, 0, 1, 1.0D, 1.0D));

        tabbedPane.insertTab("ResponseCharts", null, tab2, null, 1);

    }

    // Stop the updating thread when the window is closed
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
            stopThread = true;
        }
    });

}

From source file:org.zaproxy.zap.extension.ascan.ScanProgressDialog.java

/**
 * /*from   ww w  .ja  v  a 2  s . com*/
 */
private void initialize() {
    this.setSize(new Dimension(580, 504));

    if (site != null) {
        this.setTitle(MessageFormat.format(Constant.messages.getString("ascan.progress.title"), site));
    }

    JTabbedPane tabbedPane = new JTabbedPane();
    JPanel tab1 = new JPanel();
    tab1.setLayout(new GridBagLayout());

    JPanel hostPanel = new JPanel();
    hostPanel.setLayout(new GridBagLayout());
    hostPanel.add(new JLabel(Constant.messages.getString("ascan.progress.label.host")),
            LayoutHelper.getGBC(0, 0, 1, 0.4D));
    hostPanel.add(getHostSelect(), LayoutHelper.getGBC(1, 0, 1, 0.6D));
    tab1.add(hostPanel, LayoutHelper.getGBC(0, 0, 3, 1.0D, 0.0D));

    tab1.add(getJScrollPane(), LayoutHelper.getGBC(0, 1, 3, 1.0D, 1.0D));

    tab1.add(new JLabel(), LayoutHelper.getGBC(0, 1, 1, 1.0D, 0.0D)); // spacer
    tab1.add(getCloseButton(), LayoutHelper.getGBC(1, 2, 1, 0.0D, 0.0D));
    tab1.add(new JLabel(), LayoutHelper.getGBC(2, 1, 1, 1.0D, 0.0D)); // spacer

    tabbedPane.insertTab(Constant.messages.getString("ascan.progress.tab.progress"), null, tab1, null, 0);
    this.add(tabbedPane);

    int mins = extension.getScannerParam().getMaxChartTimeInMins();
    if (mins > 0) {
        // Treat zero mins as disabled
        JPanel tab2 = new JPanel();
        tab2.setLayout(new GridBagLayout());

        this.seriesTotal = new TimeSeries("TotalResponses"); // Name not shown, so no need to i18n
        final TimeSeriesCollection dataset = new TimeSeriesCollection(this.seriesTotal);

        this.series100 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.1xx"));
        this.series200 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.2xx"));
        this.series300 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.3xx"));
        this.series400 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.4xx"));
        this.series500 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.5xx"));

        this.seriesTotal.setMaximumItemAge(mins * 60);
        this.series100.setMaximumItemAge(mins * 60);
        this.series200.setMaximumItemAge(mins * 60);
        this.series300.setMaximumItemAge(mins * 60);
        this.series400.setMaximumItemAge(mins * 60);
        this.series500.setMaximumItemAge(mins * 60);

        dataset.addSeries(series100);
        dataset.addSeries(series200);
        dataset.addSeries(series300);
        dataset.addSeries(series400);
        dataset.addSeries(series500);

        chart = createChart(dataset);
        // Set up some vaguesly sensible colours
        chart.getXYPlot().getRenderer(0).setSeriesPaint(0, Color.BLACK); // Totals
        chart.getXYPlot().getRenderer(0).setSeriesPaint(1, Color.GRAY); // 100: Info
        chart.getXYPlot().getRenderer(0).setSeriesPaint(2, Color.GREEN); // 200: OK
        chart.getXYPlot().getRenderer(0).setSeriesPaint(3, Color.BLUE); // 300: Info
        chart.getXYPlot().getRenderer(0).setSeriesPaint(4, Color.MAGENTA); // 400: Bad req
        chart.getXYPlot().getRenderer(0).setSeriesPaint(5, Color.RED); // 500: Internal error

        final ChartPanel chartPanel = new ChartPanel(chart);
        tab2.add(chartPanel, LayoutHelper.getGBC(0, 0, 1, 1.0D, 1.0D));

        tabbedPane.insertTab(Constant.messages.getString("ascan.progress.tab.chart"), null, tab2, null, 1);
    }

    // Stop the updating thread when the window is closed
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
            stopThread = true;
        }
    });
}