Example usage for javax.swing JPanel revalidate

List of usage examples for javax.swing JPanel revalidate

Introduction

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

Prototype

public void revalidate() 

Source Link

Document

Supports deferred automatic layout.

Usage

From source file:dbseer.gui.panel.DBSeerLiveMonitorPanel.java

@Override
public synchronized void actionPerformed(ActionEvent event) {
    for (int i = 0; i < transactionRenameButtons.size(); ++i) {
        if (event.getSource() == transactionRenameButtons.get(i)) {
            String newName = (String) JOptionPane.showInputDialog(this,
                    "Enter the new name for this transaction type", "New Dataset", JOptionPane.PLAIN_MESSAGE,
                    null, null, transactionNames.get(i));

            if (newName == null || newName.trim().isEmpty()) {
                return;
            } else {
                newName = newName.trim();
                transactionNames.set(i, newName);
                transactionLabels.get(i).setText(newName);

                DefaultTableModel model = (DefaultTableModel) monitorTable.getModel();
                model.setValueAt(String.format("Current TPS of '%s' transactions", transactionNames.get(i)),
                        2 + (i * ROW_PER_TX_TYPE), 0);
                model.setValueAt(/*from  w w w  . ja v  a  2 s  . c o  m*/
                        String.format("Current average latency of '%s' transactions", transactionNames.get(i)),
                        2 + (i * ROW_PER_TX_TYPE) + 1, 0);

                //               TimeSeriesCollection collection = (TimeSeriesCollection) throughputChartPanel.getChart().getXYPlot().getDataset();
                throughputCollection.getSeries(i).setKey(newName);
                latencyCollection.getSeries(i).setKey(newName);

                //               if (DBSeerGUI.currentDataset != null)
                //               {
                //                  DBSeerGUI.currentDataset.setTransactionTypeName(i, newName);
                //               }

                for (DBSeerDataSet dataset : DBSeerGUI.liveDatasets) {
                    dataset.setTransactionTypeName(i, newName);
                }

                return;
            }
        }
    }

    for (int i = 0; i < transactionViewSampleButtons.size(); ++i) {
        if (event.getSource() == transactionViewSampleButtons.get(i)) {
            final int type = i;
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    DBSeerShowTransactionExampleFrame sampleFrame = new DBSeerShowTransactionExampleFrame(type);
                    sampleFrame.pack();
                    sampleFrame.setLocationRelativeTo(DBSeerGUI.mainFrame);
                    sampleFrame.setVisible(true);
                }
            });
        }
    }

    for (int i = 0; i < transactionEnableDisableButtons.size(); ++i) {
        if (event.getSource() == transactionEnableDisableButtons.get(i)) {
            final XYItemRenderer throughputRenderer = throughputChartPanel.getChart().getXYPlot().getRenderer();
            final XYItemRenderer latencyRenderer = latencyChartPanel.getChart().getXYPlot().getRenderer();
            final int type = i;
            final JButton button = transactionEnableDisableButtons.get(i);
            final DBSeerDataSet dataset = DBSeerGUI.liveDataset;

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    if (button.getText() == "Disable") {
                        dataset.disableTransaction(type);
                        throughputRenderer.setSeriesVisible(type, false);
                        latencyRenderer.setSeriesVisible(type, false);
                        button.setText("Enable");
                    } else if (button.getText() == "Enable") {
                        dataset.enableTransaction(type);
                        throughputRenderer.setSeriesVisible(type, true);
                        latencyRenderer.setSeriesVisible(type, true);
                        button.setText("Disable");
                    }
                }
            });
        }
    }

    for (int i = 0; i < transactionDeleteButtons.size(); ++i) {
        if (event.getSource() == transactionDeleteButtons.get(i)) {
            synchronized (LiveMonitorInfo.LOCK) {
                try {
                    DBSeerGUI.middlewareSocket.removeTransactionType(i);
                } catch (IOException e) {
                    DBSeerExceptionHandler.handleException(e);
                }

                throughputCollection.removeSeries(i);
                latencyCollection.removeSeries(i);

                DefaultTableModel model = (DefaultTableModel) monitorTable.getModel();
                int newTxSize = transactionNames.size() - 1;
                for (int j = 0; j < transactionNames.size(); ++j) {
                    model.setValueAt(String.format("Current TPS of '%s' transactions", transactionNames.get(j)),
                            2 + (j * ROW_PER_TX_TYPE), 0);
                    model.setValueAt(String.format("Current average latency of '%s' transactions",
                            transactionNames.get(j)), 2 + (j * ROW_PER_TX_TYPE) + 1, 0);
                    model.setValueAt("", 2 + (j * ROW_PER_TX_TYPE), 1);
                    model.setValueAt("", 2 + (j * ROW_PER_TX_TYPE) + 1, 1);
                }
                model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE), 0);
                model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE), 1);
                model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE) + 1, 0);
                model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE) + 1, 1);

                final JPanel panel = transactionTypesPanel;
                final JLabel label = transactionLabels.remove(i);
                final JButton renameButton = transactionRenameButtons.remove(i);
                final JButton exampleButton = transactionViewSampleButtons.remove(i);
                final JButton deleteButton = transactionDeleteButtons.remove(i);
                transactionNames.remove(i);

                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        panel.remove(label);
                        panel.remove(renameButton);
                        panel.remove(exampleButton);
                        panel.remove(deleteButton);

                        panel.revalidate();
                        panel.repaint();
                    }
                });
            }
            break;
        }
    }

}

From source file:es.emergya.ui.plugins.LayerSelectionDialog.java

private void initOptions(final JPanel list) {
    SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {

        @Override// w w  w  .jav a 2  s .co m
        protected Object doInBackground() throws Exception {
            publish(new Object[0]);
            for (CapaInformacion ci : CapaConsultas.getAllOrderedByOrden()) {
                if (ci.getOpcional() && ci.getHabilitada()) {
                    layers.add(new LayerElement(ci.getNombre(), ci.getUrl(), wasVisible(ci)));
                }
            }
            return null;
        }

        @Override
        protected void process(List<Object> chunks) {
            actualizando.setIcon(es.emergya.cliente.constants.LogicConstants.getIcon("anim_actualizando"));
        }

        @Override
        protected void done() {
            super.done();
            actualizando.setIcon(null);
            list.setLayout(new BoxLayout(list, BoxLayout.Y_AXIS));
            for (LayerElement le : layers) {
                JCheckBox cb = new JCheckBox(le.name, le.active);
                cb.setBackground(Color.WHITE);
                cb.addActionListener(LayerSelectionDialog.this);
                list.add(cb);
                list.revalidate();
            }

            // self.pack();
        }
    };
    sw.execute();
}

From source file:sentimentanalyzer.ChartController.java

public void postTheTimeSeriesChartOnTheGUI_words(JPanel timeSeriesChart, XYSeriesCollection dataset,
        String title, String y, String x, int row) {
    this.wordCountsChart = ChartFactory.createXYLineChart(title, x, y, dataset, PlotOrientation.VERTICAL, true,
            true, false);//from w w  w. ja  v a2 s.co m

    this.wordIndexesOnGraph.add(row);
    this.plot_counter = this.wordCountsChart.getXYPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    //CHECK THIS
    renderer.setBaseShapesVisible(true);

    this.plot_counter.setRenderer(renderer);
    this.plot_counter.setOutlinePaint(Color.orange);

    NumberAxis rangeAxis = (NumberAxis) this.plot_counter.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    NumberAxis domainAxis = (NumberAxis) this.plot_counter.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    this.wordCountsChart.setBackgroundPaint(Color.white);
    this.wordCountsChart.setBorderPaint(Color.orange);
    ChartPanel CP = new ChartPanel(this.wordCountsChart);

    timeSeriesChart.setLayout(new java.awt.BorderLayout());
    timeSeriesChart.add(CP, BorderLayout.CENTER);
    timeSeriesChart.revalidate();
}

From source file:sentimentanalyzer.ChartController.java

public void postTheTimeSeriesChartOnTheGUI_sentiment(JPanel timeSeriesChart, XYSeriesCollection dataset,
        String title, String y, String x, int row) {
    this.wordSentimentScore = ChartFactory.createXYLineChart(title, y, x, dataset, PlotOrientation.VERTICAL,
            true, true, false);//from   ww w.  ja  v  a 2  s.co m

    this.wordIndexesOnGraph.add(row);
    this.plot_sentiment = this.wordSentimentScore.getXYPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    //CHECK THIS
    renderer.setBaseShapesVisible(true);

    this.plot_sentiment.setRenderer(renderer);
    this.plot_sentiment.setOutlinePaint(Color.orange);

    NumberAxis rangeAxis = (NumberAxis) this.plot_sentiment.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    NumberAxis domainAxis = (NumberAxis) this.plot_sentiment.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    this.wordSentimentScore.setBackgroundPaint(Color.white);
    this.wordSentimentScore.setBorderPaint(Color.ORANGE);
    ChartPanel CP = new ChartPanel(this.wordSentimentScore);
    timeSeriesChart.setLayout(new java.awt.BorderLayout());
    timeSeriesChart.add(CP, BorderLayout.CENTER);
    timeSeriesChart.revalidate();
}

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

private void crearTabla(Pregunta pregunta) {
    JScrollPane scrollPanel = new JScrollPane();
    JPanel panel = new JPanel(new GridLayout(0, 1));

    if (pregunta.obtenerCantidadDePerfiles() > 1) {
        for (int i = 0; i < pregunta.obtenerCantidadDePerfiles(); i++) {
            JPanel p = hacerTabla(pregunta,
                    ((ResultadoPorPerfil) pregunta.obtenerResultadoPorPerfil(i)).getOpciones(),
                    ((ResultadoPorPerfil) pregunta.obtenerResultadoPorPerfil(i)).getPerfil());
            panel.add(p);/*from  w  ww .j a v a 2 s.co m*/
        }
    }
    JPanel p = hacerTabla(pregunta, pregunta.obtenerOpciones(), "Todos");
    panel.add(p);

    scrollPanel.setViewportView(panel);
    scrollPanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    JScrollBar vertical = scrollPanel.getVerticalScrollBar();
    vertical.setValue(0);
    vertical.setUnitIncrement(30);
    panelGrafica.add(scrollPanel, BorderLayout.CENTER);
    panel.repaint();
    panel.revalidate();
    panelGrafica.repaint();
    panelGrafica.revalidate();
}

From source file:Classes_Home.CriarGrafico.java

public void criargrafico(JPanel jPanel3) {
        String pcs[] = { "'HP'", "'IBM'", "'LENOVO'", "'POSITIVO'", "'NACIONAL'" };
        for (int i = 0; i <= 4; i++) {
            String query = "SELECT * FROM `cpu` WHERE marca = " + pcs[i];

            try {
                st = connection.createStatement();
                rs = st.executeQuery(query);
                if (rs.last()) {
                    int aux = rs.getRow();
                    vetorParaGrafico[i] = aux;
                }/*from   ww  w .  ja  va  2  s. com*/
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.setValue(vetorParaGrafico[0], "Quantidade", "HP");
        dataset.setValue(vetorParaGrafico[1], "Quantidade", "IBM");
        dataset.setValue(vetorParaGrafico[2], "Quantidade", "LENOVO");
        dataset.setValue(vetorParaGrafico[3], "Quantidade", "POSITIVO");
        dataset.setValue(vetorParaGrafico[4], "Quantidade", "NACIONAL");

        JFreeChart chart = ChartFactory.createBarChart3D(null, null, "Quantidade", dataset,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        CategoryItemRenderer renderer = p.getRenderer();
        renderer.setSeriesPaint(0, new Color(80, 151, 204));
        p.setRangeGridlinePaint(Color.BLACK);
        ChartPanel panel = new ChartPanel(chart);
        panel.setDomainZoomable(true);
        panel.setVisible(true);
        jPanel3.setLayout(new BorderLayout());
        jPanel3.add(panel, BorderLayout.CENTER);
        jPanel3.revalidate();
        jPanel3.repaint();
        System.gc();
    }

From source file:parts.GraphicContent.java

public void setContent(JPanel panel) {
    String sprint[] = null;/*from  ww w  .  ja v a  2 s.c  o m*/
    int taskCount[] = null;
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    try {
        Statement st = scrum.SCRUM.conexao.createStatement();
        String sql = "select COUNT(*) from sprint";
        result = st.executeQuery(sql);
        result.next();
        sprint = new String[result.getInt(1)];
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        Statement st = scrum.SCRUM.conexao.createStatement();
        String sql = "select * from sprint";
        result = st.executeQuery(sql);
        int i = 0;
        while (result.next()) {
            sprint[i] = result.getString("alias");
            i++;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    int sprintIDs[] = new int[sprint.length];

    try {
        Statement st = scrum.SCRUM.conexao.createStatement();
        String sql = "select * from sprint";
        result = st.executeQuery(sql);
        int i = 0;
        while (result.next()) {
            sprintIDs[i] = result.getInt("idsprint");
            i++;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    for (int i = 0; i < sprint.length; i++) {
        try {
            Statement st = scrum.SCRUM.conexao.createStatement();
            String sql = "select COUNT(*) from sprint_tasks  where idsprint  = " + sprintIDs[i];
            result = st.executeQuery(sql);
            while (result.next()) {
                dataset.addValue(result.getInt(1), "Tarefas", sprint[i]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    JFreeChart chart = null;
    chart = ChartFactory.createBarChart("Quantidade de tarefas por Sprint", "Sprint", "Tarefas", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.black);

    ChartPanel cp = new ChartPanel(chart);
    cp.setBounds(0, 0, panel.getWidth(), panel.getHeight());
    panel.removeAll();
    cp.setVisible(true);
    panel.add(cp);
    panel.revalidate();
    panel.repaint();
}

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  a2  s  . c  o  m
            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;
}

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

public void getBotonesPreguntas(JPanel botones) {
    GridBagConstraints gridBagConstraints;
    boolean first = false;
    botones.removeAll();// w  w  w .  j  ava 2  s  .c o  m
    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;
    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:com.rapidminer.gui.viewer.metadata.AttributeStatisticsPanel.java

/**
 * Updates the charts./*from   ww w . ja  v a2  s.  c om*/
 */
@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();
    }
}