Example usage for javax.swing JPanel removeAll

List of usage examples for javax.swing JPanel removeAll

Introduction

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

Prototype

public void removeAll() 

Source Link

Document

Removes all the components from this container.

Usage

From source file:com.polivoto.vistas.Charts.java

public void getHeader(JPanel header) {
    header.removeAll();
    GridBagConstraints gridBagConstraints;
    header.setLayout(new GridBagLayout());
    header.setBackground(Color.white);
    header.setPreferredSize(new Dimension(0, 100));
    JLabel titulo = new JLabel("<html>     <b>Votacin: </b>" + votacion.getTitulo() + "</html>");
    JLabel lugar = new JLabel("<html>     <b>Lugar: </b>" + votacion.getLugar() + "</html>");
    SimpleDateFormat sdf = new SimpleDateFormat("EEEE d' de 'MMMM' del 'yyyy, hh:mm:ss");
    JLabel fechaInicio = new JLabel(
            "<html><b>Fecha de inicio: </b>" + sdf.format(new Date(votacion.getFechaInicio())) + "</html>");
    JLabel fechaFin = new JLabel(
            "<html><b>Fecha de fin: </b>" + sdf.format(new Date(votacion.getFechaFin())) + "</html>");
    titulo.setFont(fuenteNormal);/*from  ww w . j av  a  2  s.  c om*/
    titulo.setVerticalAlignment(JLabel.CENTER);
    lugar.setFont(fuenteNormal);
    lugar.setVerticalAlignment(JLabel.CENTER);
    fechaFin.setFont(fuenteNormal);
    fechaFin.setVerticalAlignment(JLabel.CENTER);
    fechaInicio.setFont(fuenteNormal);
    fechaInicio.setVerticalAlignment(JLabel.CENTER);
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 0.1;
    gridBagConstraints.weighty = 0.1;
    gridBagConstraints.insets = new java.awt.Insets(5, 15, 5, 5);
    header.add(titulo, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 3;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 0.1;
    gridBagConstraints.weighty = 0.1;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 15);
    header.add(fechaInicio, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 0.1;
    gridBagConstraints.weighty = 0.1;
    gridBagConstraints.insets = new java.awt.Insets(5, 15, 5, 5);
    header.add(lugar, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 3;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 0.1;
    gridBagConstraints.weighty = 0.1;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 15);
    header.add(fechaFin, gridBagConstraints);

    header.repaint();
    header.revalidate();

}

From source file:com.polivoto.vistas.Charts.java

public void getBotonesPreguntas(JPanel botones) {
    GridBagConstraints gridBagConstraints;
    boolean first = false;
    botones.removeAll();
    JPanel panelRelleno = new JPanel(new BorderLayout(20, 20));
    panelRelleno.setBackground(Color.white);
    JPanel panelContainer = new JPanel(new GridLayout(0, 1, 30, 30));
    panelContainer.setBackground(Color.white);
    botones.setPreferredSize(new Dimension(250, 0));
    botones.setLayout(new GridBagLayout());
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;//from w ww. j  a va 2s.com
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 0.1;
    gridBagConstraints.weighty = 0.1;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
    botones.add(panelContainer, gridBagConstraints);
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 0.1;
    gridBagConstraints.weighty = 0.9;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
    botones.add(panelRelleno, gridBagConstraints);
    JLabel labelPreguntas = new JLabel("PREGUNTAS");
    labelPreguntas.setFont(new Font("Roboto", 1, 24));
    labelPreguntas.setHorizontalAlignment(0);
    labelPreguntas.setForeground(new Color(137, 36, 31));
    panelContainer.add(labelPreguntas);

    for (Pregunta pregunta : votacion.getPreguntas()) {
        Boton boton = new Boton("<html><div align=center>" + pregunta.getTitulo() + "</html>") {

            @Override
            public void botonClicked(Boton e) {
                crearGrafica(pregunta);
                botonActual = e;
            }
        };
        boton.setPreferredSize(new Dimension(200, 0));

        panelContainer.add(boton);
        if (!first) {
            botonActual = boton;
            first = true;
        }
    }

    botones.repaint();
    botones.revalidate();

}

From source file:st.jigasoft.dbutil.view.DUReport.java

/**
 * Adicionar coponetes a um dado panel//from w  ww.ja  v a2s.co  m
 * @param panel
 * @param chartPanels 
 */
private void addComponestesAt(JPanel panel, JComponent... chartPanels) {
    panel.removeAll();
    if (chartPanels == null)
        return;
    for (JComponent component : chartPanels)
        if (component != null) {
            panel.add(component);
            panel.updateUI();
        }
}

From source file:api3.window.sound.panel.SoundPanel.java

public void plot(PanelData data, JFreeChart chart, JPanel plotPanel) {
    chart = ChartFactory.createXYLineChart(data.name, "prbka", "warto", data.dataset,
            PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    LOG.info("PLOTTING      1");
    domainAxis = (NumberAxis) plot.getDomainAxis();
    plot.addRangeMarker(new ValueMarker(0, Color.BLACK, new BasicStroke(1)));

    ChartPanel chartPanel = new ChartPanel(chart);
    Border border = BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createEtchedBorder());
    chartPanel.setBorder(border);//from  w  w w.  j a  v  a 2 s .com
    LOG.info("PLOTTING      2");
    plotPanel.removeAll();
    plotPanel.add(chartPanel);
    plotPanel.revalidate();
    LOG.info("PLOTTING      3");
}

From source file:com.rapidminer.gui.viewer.metadata.AttributeStatisticsPanel.java

/**
 * Updates the charts./*from w w  w  . j  a  va  2 s .  c  o  m*/
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private void updateCharts() {
    for (int i = 0; i < listOfChartPanels.size(); i++) {
        JPanel panel = listOfChartPanels.get(i);
        panel.removeAll();
        final ChartPanel chartPanel = new ChartPanel(getModel().getChartOrNull(i)) {

            private static final long serialVersionUID = -6953213567063104487L;

            @Override
            public Dimension getPreferredSize() {
                return DIMENSION_CHART_PANEL_ENLARGED;
            }
        };
        chartPanel.setPopupMenu(null);
        chartPanel.setBackground(COLOR_TRANSPARENT);
        chartPanel.setOpaque(false);
        chartPanel.addMouseListener(enlargeAndHoverAndPopupMouseAdapter);
        panel.add(chartPanel, BorderLayout.CENTER);

        JPanel openChartPanel = new JPanel(new GridBagLayout());
        openChartPanel.setOpaque(false);

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.fill = GridBagConstraints.NONE;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;

        JButton openChartButton = new JButton(OPEN_CHART_ACTION);
        openChartButton.setOpaque(false);
        openChartButton.setContentAreaFilled(false);
        openChartButton.setBorderPainted(false);
        openChartButton.addMouseListener(enlargeAndHoverAndPopupMouseAdapter);
        openChartButton.setHorizontalAlignment(SwingConstants.LEFT);
        openChartButton.setHorizontalTextPosition(SwingConstants.LEFT);
        openChartButton.setIcon(null);
        Font font = openChartButton.getFont();
        Map attributes = font.getAttributes();
        attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
        openChartButton.setFont(font.deriveFont(attributes).deriveFont(10.0f));

        openChartPanel.add(openChartButton, gbc);

        panel.add(openChartPanel, BorderLayout.SOUTH);
        panel.revalidate();
        panel.repaint();
    }
}

From source file:sentimentanalyzer.ChartController.java

public void createAndPopulatePieChart(JPanel pnlPieChart, double positiveValue, double negativeValue,
        double neutralValue) {

    DefaultPieDataset data = new DefaultPieDataset();

    data.setValue(Pos, positiveValue /*count for 1 */);
    data.setValue(Neu, neutralValue /*count for 0 */);
    data.setValue(Neg, negativeValue /*count for -1 */);

    JFreeChart chart = ChartFactory.createPieChart("Sent. Distr. for Testing", data, false, // legend?
            false, // tooltips?
            false // URLs?
    );//from  w ww .j a va2s . c  o m
    ChartPanel CP = new ChartPanel(chart);

    PiePlot plot = (PiePlot) chart.getPlot();

    plot.setSectionPaint("Pie chart is not available", Color.LIGHT_GRAY);
    plot.setExplodePercent(Pos, 0.02);
    plot.setExplodePercent(Neg, 0.02);
    plot.setExplodePercent(Neu, 0.02);

    double sum = positiveValue + negativeValue + neutralValue;
    int z = (int) sum;

    //Customize PieChart to show absolute values and percentages;

    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0.00%"));
    plot.setLabelGenerator(gen);

    TextTitle legendText = new TextTitle("The total number of tweets: " + z);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);

    pnlPieChart.removeAll();

    pnlPieChart.setLayout(new java.awt.BorderLayout());
    pnlPieChart.add(CP, BorderLayout.CENTER);

}

From source file:net.sf.mzmine.chartbasics.ChartLogics.java

/**
 * calculates the correct height with multiple iterations Domain and Range axes need to share the
 * same unit (e.g. mm)//from   w w w.  ja v  a  2 s.  co  m
 * 
 * @param myChart
 * @param copyToNewPanel
 * @param dataWidth width of data
 * @param axis for width calculation
 * @return
 */
public static double calcHeightToWidth(ChartPanel myChart, double chartWidth, double estimatedHeight,
        int iterations, boolean copyToNewPanel) {
    // if(myChart.getChartRenderingInfo()==null ||
    // myChart.getChartRenderingInfo().getChartArea()==null ||
    // myChart.getChartRenderingInfo().getChartArea().getWidth()==0)
    // result
    double height = estimatedHeight;
    double lastH = height;

    makeChartResizable(myChart);

    // paint on a ghost panel
    JPanel parent = (JPanel) myChart.getParent();
    JPanel p = copyToNewPanel ? new JPanel() : parent;
    if (copyToNewPanel)
        p.add(myChart, BorderLayout.CENTER);
    try {
        for (int i = 0; i < iterations; i++) {
            // paint on ghost panel with estimated height (if copy panel==true)
            myChart.setSize((int) chartWidth, (int) estimatedHeight);
            myChart.paintImmediately(myChart.getBounds());

            XYPlot plot = (XYPlot) myChart.getChart().getPlot();
            ChartRenderingInfo info = myChart.getChartRenderingInfo();
            Rectangle2D dataArea = info.getPlotInfo().getDataArea();
            Rectangle2D chartArea = info.getChartArea();

            // calc title space: will be added later to the right plot size
            double titleWidth = chartArea.getWidth() - dataArea.getWidth();
            double titleHeight = chartArea.getHeight() - dataArea.getHeight();

            // calc right plot size with axis dim.
            // real plot width is given by factor;
            double realPW = chartWidth - titleWidth;

            // ranges
            ValueAxis domainAxis = plot.getDomainAxis();
            org.jfree.data.Range x = domainAxis.getRange();
            ValueAxis rangeAxis = plot.getRangeAxis();
            org.jfree.data.Range y = rangeAxis.getRange();

            // real plot height can be calculated by
            double realPH = realPW / x.getLength() * y.getLength();

            // the real height
            height = realPH + titleHeight;

            // for next iteration
            estimatedHeight = height;
            if ((int) lastH == (int) height)
                break;
            else
                lastH = height;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    if (copyToNewPanel) {
        // reset to frame
        p.removeAll();
        parent.add(myChart);
    }

    return height;
}

From source file:com.smanempat.controller.ControllerEvaluation.java

private void showChart(int nilaiK, double[][] evalValue, JPanel panelChart, JPanel panelChart1,
        JPanel panelChart2) {//  w w w .  ja  v a 2 s . com
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(evalValue[0][0], "Kriteria", "Accuracy");
    dataset.addValue(evalValue[1][0], "Kriteria", "Recall");
    dataset.addValue(evalValue[2][0], "Kriteria", "Precision");

    JFreeChart lineChart = ChartFactory.createLineChart("Grafik Hasil Pengujian Single Test", "Kriteria",
            "Persentase", dataset, PlotOrientation.VERTICAL, false, true, false);

    CategoryPlot linePlot = lineChart.getCategoryPlot();
    LineAndShapeRenderer lineRender = new LineAndShapeRenderer();
    lineRender.setBaseShapesVisible(true);
    lineRender.setDrawOutlines(true);
    lineRender.setUseFillPaint(true);
    lineRender.setBaseFillPaint(Color.white);
    lineRender.setSeriesStroke(0, new BasicStroke(1.0f));
    lineRender.setSeriesOutlineStroke(0, new BasicStroke(5.0f));
    lineRender.setSeriesShape(0, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
    linePlot.setRenderer(lineRender);

    ChartPanel cp = new ChartPanel(lineChart);
    panelChart.removeAll();
    panelChart.add(cp);
    panelChart.validate();

}

From source file:org.glotaran.core.datadisplayers.multispec.MultiSpecEditorTopComponent.java

private JFreeChart createXYPlot(PlotOrientation orient, AxisLocation axLoc, double[] axisValues, JPanel panel,
        boolean domInvert, CrosshairOverlay overlay) {
    JFreeChart subchart;//w  w w.ja va  2s  . c om
    XYSeriesCollection chartDataset = new XYSeriesCollection();
    subchart = ChartFactory.createXYLineChart(null, null, null, chartDataset, orient, false, false, false);
    if (axisValues[axisValues.length - 1] < axisValues[0]) {
        subchart.getXYPlot().getDomainAxis().setUpperBound(axisValues[0]);
        subchart.getXYPlot().getDomainAxis().setInverted(domInvert);
    } else {
        subchart.getXYPlot().getDomainAxis().setUpperBound(axisValues[axisValues.length - 1]);
    }

    XYPlot plot = (XYPlot) subchart.getPlot();
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);
    plot.getDomainAxis().setAutoRange(true);
    plot.setDomainAxisLocation(axLoc);
    plot.setRangeAxisLocation(axLoc);
    plot.getDomainAxis().setInverted(domInvert);

    GraphPanel subchartPanel = new GraphPanel(subchart);
    if (overlay != null) {
        subchartPanel.addOverlay(overlay);
    }
    panel.removeAll();
    panel.setLayout(new BorderLayout());
    subchartPanel.setMinimumDrawHeight(0);
    subchartPanel.setMinimumDrawWidth(0);
    panel.add(subchartPanel);
    return subchart;

}

From source file:it.imtech.metadata.MetaUtility.java

private JComboBox addClassificationChoice(JPanel choice, final String sequence, final String panelname) {

    int selected = 0;
    int index = 0;
    int count = 1;

    for (Map.Entry<String, String> vc : availableClassifications.entrySet()) {
        if (count == 1 && !selectedClassificationList.containsKey(panelname + "---" + sequence)) {
            selected = index;//from   w  ww .j  av a2s .  com
            selectedClassificationList.put(panelname + "---" + sequence, vc.getKey());
        }

        if (selectedClassificationList.containsKey(panelname + "---" + sequence)) {
            if (selectedClassificationList.get(panelname + "---" + sequence).equals(vc.getKey())) {
                selected = index;
            }
        }
        index++;
    }
    try {
        classifications_reader(sequence, panelname);
    } catch (Exception ex) {
        logger.error(ex.getMessage());
    }

    final ComboMapImpl model = new ComboMapImpl();
    model.putAllLinked(availableClassifications);

    JComboBox result = new javax.swing.JComboBox(model);

    result.setSelectedIndex(selected);
    model.specialRenderCombo(result);

    result.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            JComboBox comboBox = (JComboBox) event.getSource();
            Map.Entry<String, String> c = (Map.Entry<String, String>) comboBox.getSelectedItem();

            selectedClassificationList.put(panelname + "---" + sequence, c.getKey());

            BookImporter.getInstance()
                    .createComponentMap(BookImporter.getInstance().metadatapanels.get(panelname).getPanel());
            JPanel innerPanel = (JPanel) BookImporter.getInstance()
                    .getComponentByName(panelname + "---ImPannelloClassif---" + sequence);
            innerPanel.removeAll();

            try {
                classifications_reader(sequence, panelname);
                addClassification(innerPanel, classificationMID, sequence, panelname);
            } catch (Exception ex) {
                logger.error(ex.getMessage());
            }

            innerPanel.revalidate();
            BookImporter.getInstance().setCursor(null);
        }
    });

    return result;
}