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:moviedatas.View.SpiderWebChart.java

public void refreshChart(JPanel panel, int duration, double ratio, double score, double recency, int fbLikes) {
    panel.removeAll();/* www. j  av a 2  s.  c o m*/
    panel.revalidate(); // This removes the old chart 
    spiderChart = createChart(createDataset(duration, ratio, score, recency, fbLikes));
    spiderChart.clearSubtitles();
    chartPanel = new ChartPanel(spiderChart);
    panel.setLayout(new BorderLayout());
    panel.add(chartPanel);
    panel.setPreferredSize(new Dimension(300, 300));
    panel.repaint(); // This method makes the new chart appear
}

From source file:net.daboross.outputtablesclient.gui.OutputInterface.java

@Override
public void onUpdate(final RobotTable table, final String key, final String value, final UpdateAction action) {
    if (!application.getOutput().getNameTable().contains(table.getName())) {
        return;/*from ww w  .j a v  a2  s .c o  m*/
    }
    if (action == UpdateAction.NEW) {
        //            if (key.equalsIgnoreCase(":RangeGUI")) {
        //                Output.oLog("Range: %s", value);
        //                try {
        //                    application.getCustomInterface().setTo(Double.parseDouble(value));
        //                } catch (NumberFormatException ex) {
        //                    Output.oLog("Invalid range '%s'", value);
        //                }
        //            }
        ensureTableExists(table.getName());
        JPanel panel = new JPanel(new GridBagLayout());
        panel.setBorder(new LineBorder(Color.BLACK));
        tableKeyAndKeyToValuePanel.get(table.getName()).put(key, panel);

        JLabel keyLabel = new JLabel(key);
        keyLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
        panel.add(keyLabel, new GBC().fill(GridBagConstraints.VERTICAL).gridy(0));

        JSeparator separator = new JSeparator(JSeparator.VERTICAL);
        separator.setPreferredSize(new Dimension(2, 20));
        panel.add(separator, new GBC().fill(GridBagConstraints.VERTICAL).gridy(0));

        JLabel valueLabel = new JLabel(value);
        valueLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
        panel.add(valueLabel, new GBC().fill(GridBagConstraints.VERTICAL).gridy(0));
        tableKeyAndKeyToValueLabel.get(table.getName()).put(key, valueLabel);

        JPanel parentPanel = tableKeyToTablePanel.get(table.getName());
        parentPanel.add(panel);
        parentPanel.revalidate();
    } else if (action == UpdateAction.UPDATE) {
        //            if (key.equalsIgnoreCase(":RangeGUI")) {
        //                Output.oLog("Range: %s", value);
        //                try {
        //                    application.getCustomInterface().setTo(Double.parseDouble(value));
        //                } catch (NumberFormatException ex) {
        //                    Output.oLog("Invalid range '%s'", value);
        //                }
        //            }
        ensureTableExists(table.getName());
        JLabel valueLabel = tableKeyAndKeyToValueLabel.get(table.getName()).get(key);
        valueLabel.setText(value);
    } else if (action == UpdateAction.DELETE) {
        if (tableKeyToTablePanel.get(table.getName()) == null) {
            return;
        }
        JPanel parentPanel = tableKeyToTablePanel.get(table.getName());
        JPanel valuePanel = tableKeyAndKeyToValuePanel.get(table.getName()).remove(key);
        parentPanel.remove(valuePanel);
        parentPanel.revalidate();
    }
}

From source file:net.daboross.outputtablesclient.gui.OutputInterface.java

@Override
public void onTableCleared(final RobotTable table) {
    if (!application.getOutput().getNameTable().contains(table.getName())) {
        return;//  www.j  a  v a  2 s .c  o m
    }
    if (tableKeyToTablePanel.get(table.getName()) == null) {
        return;
    }
    JPanel parentPanel = tableKeyToTablePanel.get(table.getName());
    if (parentPanel == null) {
        return;
    }
    tableKeyAndKeyToValuePanel.get(table.getName()).values().forEach(parentPanel::remove);
    parentPanel.revalidate();
    tableKeyAndKeyToValuePanel.get(table.getName()).clear();
}

From source file:de.main.sessioncreator.ReportingHelper.java

public void addReport(JPanel jp) {
    jp.removeAll();//  w  w w . java  2  s.  co m
    PieDataset dataset = createDataset();
    // based on the dataset we create the chart
    JFreeChart chart = createChart(dataset, "Sessions by Tester");
    // we put the chart into a panel
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.updateUI();
    chartPanel.setSize(490, 350);

    jp.revalidate();
    jp.setOpaque(true);
    jp.add(chartPanel);
    jp.revalidate();
    jp.setVisible(true);
    jp.setSize(700, 500);
    jp.revalidate();
    jp.repaint();
}

From source file:com.romraider.logger.ecu.ui.handler.dash.DialGaugeStyle.java

private void refreshChart(final JPanel panel) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JFreeChart chart = buildChart();
            ChartPanel chartPanel = new ChartPanel(chart);
            chartPanel.setPreferredSize(getChartSize());
            panel.removeAll();//from www  .jav  a 2  s.  c  om
            panel.add(chartPanel);
            panel.revalidate();
        }
    });
}

From source file:Main.java

public Main() {
    JPanel parentPanel = new JPanel();
    parentPanel.setLayout(new BorderLayout(10, 10));

    JPanel childPanel1 = new JPanel();
    childPanel1.setBackground(Color.red);
    childPanel1.setPreferredSize(new Dimension(300, 40));

    JPanel childPanel2 = new JPanel();
    childPanel2.setBackground(Color.blue);
    childPanel2.setPreferredSize(new Dimension(800, 600));

    JButton myButton = new JButton("Add Component ");
    myButton.addActionListener(e -> {
        parentPanel.remove(childPanel1);
        parentPanel.add(childPanel2, BorderLayout.CENTER);
        parentPanel.revalidate();
        parentPanel.repaint();/*from   w  w  w  .j  a v a2s  . co  m*/
        pack();
    });
    setLocation(10, 200);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    parentPanel.add(childPanel1, BorderLayout.CENTER);
    parentPanel.add(myButton, BorderLayout.SOUTH);
    add(parentPanel);
    pack();
    setVisible(true);
}

From source file:com.igormaznitsa.sciareto.notifications.NotificationManager.java

public void showNotification(@Nullable final Image icon, @Nullable final String title, @Nonnull final Type type,
        @Nonnull final JComponent component) {
    Utils.safeSwingCall(new Runnable() {
        @Override//from ww  w  .  j  a v  a 2  s.  c  o m
        public void run() {
            final JPanel stack = Main.getApplicationFrame().getStackPanel();

            Color color = Color.WHITE;
            switch (type) {
            case ERROR:
                color = new Color(0xFFCCCC, false);
                break;
            case WARN:
                color = new Color(0xFFFF99, false);
                break;
            case INFO:
                color = new Color(0xCCFFCC, false);
                break;
            }

            stack.add(new MessagePanel(icon, title, color, component), 0);
            stack.revalidate();
            Main.getApplicationFrame().getGlassPane().setVisible(true);
        }
    });
}

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  .  c  om*/
    LOG.info("PLOTTING      2");
    plotPanel.removeAll();
    plotPanel.add(chartPanel);
    plotPanel.revalidate();
    LOG.info("PLOTTING      3");
}

From source file:ac.openmicrolabs.view.gui.OMLLoggerView.java

private JPanel createContentPane(final TimeSeriesCollection t, final String graphTitle,
        final double graphTimeRange, final String[] signals) {

    btmPanel.remove(reportButton);/*  w w  w  .j a v  a2  s. co m*/

    chanLabel = new JLabel[signals.length];

    int activeSignalCount = 0;
    for (int i = 0; i < signals.length; i++) {
        chanLabel[i] = new JLabel(h.format("label", (char) ((i / PIN_COUNT) + ASCII_OFFSET) + "-0x"
                + String.format("%02x", (i % PIN_COUNT) + SLAVE_BITS).toUpperCase()));
        chanLabel[i].setHorizontalAlignment(JLabel.CENTER);
        if (signals[i] != null) {
            activeSignalCount++;
        } else {
            chanLabel[i].setEnabled(false);
        }
    }

    typeLabel = new JLabel[activeSignalCount];
    valLabel = new JLabel[activeSignalCount];
    minLabel = new JLabel[activeSignalCount];
    maxLabel = new JLabel[activeSignalCount];
    avgLabel = new JLabel[activeSignalCount];

    int index = 0;
    for (int i = 0; i < signals.length; i++) {
        if (signals[i] != null) {
            typeLabel[index] = new JLabel(h.format("body", signals[i]));
            typeLabel[index].setHorizontalAlignment(JLabel.CENTER);
            index++;
        }
    }

    for (int i = 0; i < activeSignalCount; i++) {
        valLabel[i] = new JLabel();
        valLabel[i].setHorizontalAlignment(JLabel.CENTER);
        minLabel[i] = new JLabel();
        minLabel[i].setHorizontalAlignment(JLabel.CENTER);
        maxLabel[i] = new JLabel();
        maxLabel[i].setHorizontalAlignment(JLabel.CENTER);
        avgLabel[i] = new JLabel();
        avgLabel[i].setHorizontalAlignment(JLabel.CENTER);
    }

    // Set up main panel.
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(null);
    mainPanel.setBackground(Color.white);

    // Create graph.
    snsChart = ChartFactory.createTimeSeriesChart(graphTitle, GRAPH_X_LABEL, GRAPH_Y_LABEL, t, true, true,
            false);
    final XYPlot plot = snsChart.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(graphTimeRange);
    axis = plot.getRangeAxis();
    axis.setRange(graphMinY, graphMaxY);

    ChartPanel snsChartPanel = new ChartPanel(snsChart);
    snsChartPanel.setPreferredSize(new Dimension(FRAME_WIDTH - PAD20, GRAPH_HEIGHT - PAD10));

    // Set up graph panel.
    final JPanel graphPanel = new JPanel();
    graphPanel.setSize(FRAME_WIDTH - PAD20, GRAPH_HEIGHT);
    graphPanel.setLocation(0, 0);
    graphPanel.setBackground(Color.white);
    graphPanel.add(snsChartPanel);

    // Set up results panel.
    final JPanel resultsPanel = createResultsPane();

    // Set up scroll pane.
    final JScrollPane scrollPane = new JScrollPane(resultsPanel);
    scrollPane.setSize(FRAME_WIDTH - PAD20, FRAME_HEIGHT - BTM_HEIGHT - GRAPH_HEIGHT + PAD8);
    scrollPane.setLocation(PAD5, GRAPH_HEIGHT);
    scrollPane.setBackground(Color.white);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

    // Set results panel size.
    resultsPanel.setPreferredSize(new Dimension(PAD40 + (signals.length * RESULTS_COL_WIDTH),
            FRAME_HEIGHT - BTM_HEIGHT - GRAPH_HEIGHT - PAD120));
    resultsPanel.revalidate();

    // Set up bottom panel.
    btmPanel.setLayout(null);
    btmPanel.setSize(FRAME_WIDTH, BTM_HEIGHT);
    btmPanel.setLocation(0, this.getHeight() - BTM_HEIGHT);
    btmPanel.setBackground(Color.white);

    // Instantiate bottom panel objects.
    footerLabel.setSize(LABEL_WIDTH, LABEL_HEIGHT);
    footerLabel.setLocation(LABEL_X, LABEL_Y);
    footerLabel.setText("");

    doneButton.setIcon(new ImageIcon("img/22x22/stop.png"));
    doneButton.setSize(DONE_WIDTH, DONE_HEIGHT);
    doneButton.setLocation(FRAME_WIDTH - PAD20 - doneButton.getWidth(), PAD15);

    progressBar = new JProgressBar();
    progressBar.setSize(FRAME_WIDTH - PAD40 - doneButton.getWidth() - footerLabel.getWidth(), PAD20);
    progressBar.setValue(0);
    progressBar.setLocation(footerLabel.getWidth() + PAD10, PAD22);

    // Populate bottom panel.
    btmPanel.add(footerLabel);
    btmPanel.add(progressBar);
    btmPanel.add(doneButton);

    // Populate main panel.
    mainPanel.add(graphPanel);
    mainPanel.add(scrollPane);
    mainPanel.add(btmPanel);

    return mainPanel;
}

From source file:loansystem.visual.panel.StartPage.java

private void dibujarGrafico(DefaultCategoryDataset datos, int tipoGrafico, String titulo, String ejeX,
        String ejeY, PlotOrientation orientacion, JPanel contenedor) {
    JFreeChart grafica = null;/*from w  w  w  .  ja  v  a  2  s.  c  om*/

    switch (tipoGrafico) {
    case BAR:
        grafica = ChartFactory.createBarChart3D(titulo, ejeX, ejeY, datos, orientacion, true, true, false);
        break;
    case LINE:

        break;

    case PIE:

        break;
    }

    grafica.getTitle().setPaint(Color.black);

    CategoryPlot p = grafica.getCategoryPlot();
    p.setRangeGridlinePaint(Color.black);

    CategoryItemRenderer renderer = ((CategoryPlot) grafica.getPlot()).getRenderer();
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER);
    renderer.setBasePositiveItemLabelPosition(position);

    int style = Font.BOLD;
    Font font = new Font("Tahoma", style, 12);
    renderer.setItemLabelFont(font);

    ChartPanel panel = new ChartPanel(grafica);
    contenedor.add(panel);
    contenedor.revalidate();
    contenedor.repaint();
}