Example usage for javax.swing JPanel repaint

List of usage examples for javax.swing JPanel repaint

Introduction

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

Prototype

public void repaint() 

Source Link

Document

Repaints this component.

Usage

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());

    JPanel upper = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    upper.setLayout(gridbag);//from  w w w  .j  av a2  s . c  o m
    GridBagConstraints gbc = new GridBagConstraints();

    JButton toolbar1 = new JButton("toolbar1");
    JButton toolbar2 = new JButton("toolbar2");
    JButton toolbar3 = new JButton("toolbar3");

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.WEST;
    upper.add(toolbar1, gbc);

    gbc.gridx = 1;
    gbc.anchor = GridBagConstraints.CENTER;
    upper.add(toolbar2, gbc);

    gbc.gridx = 2;
    gbc.anchor = GridBagConstraints.EAST;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    upper.add(toolbar3, gbc);

    add(upper, BorderLayout.NORTH);

    JPanel something = new JPanel();
    something.setBackground(Color.WHITE);
    something.setPreferredSize(new Dimension(600, 600));
    something.repaint();
    add(something, BorderLayout.CENTER);

    pack();
    setVisible(true);
}

From source file:SplashScreenTest.java

/**
 * This method displays a frame with the same image as the splash screen.
 *//*ww  w.j  ava  2  s. c o  m*/
private static void init2() {
    final Image img = Toolkit.getDefaultToolkit().getImage(splash.getImageURL());

    final JFrame splashFrame = new JFrame();
    splashFrame.setUndecorated(true);

    final JPanel splashPanel = new JPanel() {
        public void paintComponent(Graphics g) {
            g.drawImage(img, 0, 0, null);
        }
    };

    final JProgressBar progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    splashPanel.setLayout(new BorderLayout());
    splashPanel.add(progressBar, BorderLayout.SOUTH);

    splashFrame.add(splashPanel);
    splashFrame.setBounds(splash.getBounds());
    splashFrame.setVisible(true);

    new SwingWorker<Void, Integer>() {
        protected Void doInBackground() throws Exception {
            try {
                for (int i = 0; i <= 100; i++) {
                    publish(i);
                    Thread.sleep(100);
                }
            } catch (InterruptedException e) {
            }
            return null;
        }

        protected void process(List<Integer> chunks) {
            for (Integer chunk : chunks) {
                progressBar.setString("Loading module " + chunk);
                progressBar.setValue(chunk);
                splashPanel.repaint(); // because img is loaded asynchronously
            }
        }

        protected void done() {
            splashFrame.setVisible(false);

            JFrame frame = new JFrame();
            frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setTitle("SplashScreenTest");
            frame.setVisible(true);
        }
    }.execute();
}

From source file:cmsc105_mp2.Plotting.java

public void createGraphs(ArrayList<Data> d, double threshold, float window) {

    JPanel main = new JPanel();
    for (Data data : d) {

        JPanel jPanel = new Panels(data, window, threshold);
        main.add(jPanel);/*from   w w  w  .  j a  v  a 2s  .c o m*/
        main.revalidate();
        main.repaint();

    }

    this.setSize(600, 350);
    jScrollPane1.getViewport().add(main);
    this.validate();
    this.repaint();
    this.pack();
}

From source file:ANNFileDetect.GraphingClass.java

public void drawchartFromInt(Integer[] values) throws IOException {
    DefaultCategoryDataset ds = new DefaultCategoryDataset();
    for (int i = 0; i < values.length; i++) {
        //double a = (double) i;
        ds.addValue(i, String.valueOf(i), String.valueOf(values[i]));
        //ds.addValue((double)i, "Times", values[i]);
    }/* w ww  .j  av  a  2 s.c o  m*/
    JFreeChart chart = ChartFactory.createBarChart("chart", "quantity", "value", ds, PlotOrientation.VERTICAL,
            true, true, false);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setSize(1200, 700);
    JPanel jf = new JPanel();
    jf.setSize(1300, 800);
    chartPanel.setVisible(true);
    chartPanel.setZoomAroundAnchor(true);
    chartPanel.setDomainZoomable(true);
    jf.add(chartPanel);
    JLabel jl = new JLabel("hello!");
    jf.add(jl);
    jf.setVisible(true);
    jf.repaint();
    //jf.setAlwaysOnTop(true);
}

From source file:electroStaticUI.ElectroStaticUIContainer.java

public void addPanelToContainer(JPanel panelToAdd, String borderLayout) {
    container.add(panelToAdd, borderLayout);
    panelToAdd.repaint();
    container.revalidate();//from   w  ww .  ja  va2s .co  m
}

From source file:com.polivoto.vistas.acciones.Datos.java

public void setBarChartIn(JPanel panel) {
    CategoryDataset dataset = crearDatasetBar();
    JFreeChart chart = createChartBar(dataset);
    ChartPanel barChart = new ChartPanel(chart);
    barChart.setBounds(panel.getVisibleRect());
    panel.removeAll();//ww  w.j  a  va2 s  . c o m
    panel.add(barChart);
    panel.repaint();
}

From source file:gui.images.CodebookVectorProfilePanel.java

/**
 * Sets the data to be shown.//from  w  w  w  .j  a v  a 2s  .  c om
 *
 * @param occurrenceProfile Double array that is the neighbor occurrence
 * profile of this visual word.
 * @param codebookIndex Integer that is the index of this visual word.
 * @param classColors Color[] of class colors.
 * @param classNames String[] of class names.
 */
public void setResults(double[] occurrenceProfile, int codebookIndex, Color[] classColors,
        String[] classNames) {
    int numClasses = Math.min(classNames.length, occurrenceProfile.length);
    this.codebookIndex = codebookIndex;
    this.occurrenceProfile = occurrenceProfile;
    DefaultPieDataset pieData = new DefaultPieDataset();
    for (int cIndex = 0; cIndex < numClasses; cIndex++) {
        pieData.setValue(classNames[cIndex], occurrenceProfile[cIndex]);
    }
    JFreeChart chart = ChartFactory.createPieChart3D("codebook vect " + codebookIndex, pieData, true, true,
            false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    PieRenderer prend = new PieRenderer(classColors);
    prend.setColor(plot, pieData);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(140, 140));
    chartPanel.setVisible(true);
    chartPanel.revalidate();
    chartPanel.repaint();
    JPanel jp = new JPanel();
    jp.setPreferredSize(new Dimension(140, 140));
    jp.setMinimumSize(new Dimension(140, 140));
    jp.setMaximumSize(new Dimension(140, 140));
    jp.setSize(new Dimension(140, 140));
    jp.setLayout(new FlowLayout());
    jp.add(chartPanel);
    jp.setVisible(true);
    jp.validate();
    jp.repaint();

    JFrame frame = new JFrame();
    frame.setBackground(Color.WHITE);
    frame.setUndecorated(true);
    frame.getContentPane().add(jp);
    frame.pack();
    BufferedImage bi = new BufferedImage(jp.getWidth(), jp.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = bi.createGraphics();
    jp.print(graphics);
    graphics.dispose();
    frame.dispose();
    imPanel.removeAll();
    imPanel.setImage(bi);
    imPanel.setVisible(true);
    imPanel.revalidate();
    imPanel.repaint();
}

From source file:moviedatas.View.SpiderWebChart.java

public void refreshChart(JPanel panel, int duration, double ratio, double score, double recency, int fbLikes) {
    panel.removeAll();/*from w  w  w.  j  a v  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: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();/*w w w .j a  v  a 2  s. c om*/
        parentPanel.repaint();
        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.polivoto.vistas.acciones.Datos.java

public void setPieChartIn(JPanel panel) {
    PieDataset dataset = crearDatasetPie();
    JFreeChart chart = null;//from   w  ww. jav a 2s  .  com
    try {
        chart = crearChartPie(dataset, ac.getPreguntas().getJSONObject(pox).getString("pregunta"));
    } catch (JSONException ex) {
        ex.printStackTrace();
    }
    ChartPanel pie = new ChartPanel(chart);
    pie.setBounds(panel.getVisibleRect());
    panel.removeAll();
    panel.add(pie);
    panel.repaint();
}