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

public static void main(String[] args) {
    JFrame capture = new JFrame();
    capture.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Toolkit kit = Toolkit.getDefaultToolkit();
    final Dimension d = kit.getScreenSize();
    capture.setSize(d);/*from  w  ww. j  a va2 s. c om*/

    Rectangle rect = new Rectangle(d);
    try {
        Robot robot = new Robot();
        final BufferedImage image = robot.createScreenCapture(rect);
        image.flush();
        JPanel panel = new JPanel() {
            public void paintComponent(Graphics g) {
                g.drawImage(image, 0, 0, d.width, d.height, this);
            }
        };
        panel.setOpaque(false);
        panel.prepareImage(image, panel);
        panel.repaint();
        capture.getContentPane().add(panel);
    } catch (Exception e) {
        e.printStackTrace();
    }

    capture.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    BoundedRangeModel model = new DefaultBoundedRangeModel();
    BlockedColorLayerUI layerUI = new BlockedColorLayerUI();
    JPanel p = new JPanel(new GridLayout(2, 1, 12, 12));

    p.add(new JLayer<JProgressBar>(new JProgressBar(model), layerUI));

    JPanel box = new JPanel();
    box.add(new JButton(new AbstractAction("+10") {
        private int i = 0;

        @Override//w  w w  .  j  a va 2 s. c o m
        public void actionPerformed(ActionEvent e) {
            model.setValue(i = (i >= 100) ? 0 : i + 10);
        }
    }));

    p.repaint();

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(p, BorderLayout.NORTH);
    panel.add(box, BorderLayout.SOUTH);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(panel);
    f.setSize(320, 240);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createLineBorder(Color.RED));
    BoxLayout mgr = new BoxLayout(panel, BoxLayout.Y_AXIS);
    panel.setLayout(mgr);/*from  w  w  w. ja va 2  s .  c o  m*/
    for (int i = 0; i < 5; i++) {
        JButton button = new JButton("Remove Hello World " + (i + 1));
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        button.addActionListener(e -> {
            panel.remove(button);
            panel.revalidate();
            panel.repaint();
        });
        panel.add(button);
    }
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Runnable r = new Runnable() {
        @Override//from   w  w  w  .  j  a  va2 s. c o  m
        public void run() {
            JPanel gui = new JPanel();

            final AnimatedImage[] tiles = new AnimatedImage[2];
            for (int ii = 0; ii < tiles.length; ii++) {
                tiles[ii] = new AnimatedImage();
                gui.add(new JLabel(new ImageIcon(tiles[ii])));
            }
            ActionListener listener = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    for (int i = 0; i < tiles.length; i++) {
                        tiles[i].paintImage();
                        gui.repaint();
                    }
                }
            };
            Timer timer = new Timer(50, listener);
            timer.start();

            JOptionPane.showMessageDialog(null, gui);
            timer.stop();
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:MainClass.java

public static void main(String[] args) {
    JFrame f = new JFrame();

    final JPanel p1 = new JPanel();
    p1.add(new JLabel("GlassPane Example"));
    JButton show = new JButton("Show");
    p1.add(show);/*from   w  w  w . j av a  2  s.  c o  m*/
    p1.add(new JButton("No-op"));
    f.getContentPane().add(p1);

    final JPanel glass = (JPanel) f.getGlassPane();

    glass.setVisible(true);
    glass.setLayout(new GridBagLayout());
    JButton glassButton = new JButton("Hide");
    glass.add(glassButton);

    f.setSize(150, 80);
    f.setVisible(true);

    show.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            glass.setVisible(true);
            p1.repaint();
        }
    });
    glassButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            glass.setVisible(false);
            p1.repaint();
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout(2, 3));

    JPanel buttonConstrsint = new JPanel(new FlowLayout(FlowLayout.CENTER));
    JButton getQuotesButton = new JButton("Load");
    buttonConstrsint.add(getQuotesButton);
    gui.add(buttonConstrsint, BorderLayout.NORTH);

    getQuotesButton.addActionListener(e -> {
        String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" };

        Object[][] data = { { "A", "B", "Snowboarding", new Integer(5), new Boolean(false) },
                { "C", "D", "Pool", new Integer(10), new Boolean(false) } };

        JTable table = new JTable(data, columnNames);

        JScrollPane scrollPane = new JScrollPane(table);
        table.setFillsViewportHeight(true);

        gui.add(scrollPane, BorderLayout.CENTER);
        gui.revalidate();//  w  ww.  jav a  2s .c om
        gui.repaint();
    });

    JOptionPane jOptionPane = new JOptionPane(gui);

    JDialog dialog = jOptionPane.createDialog(new JFrame(), "title");
    dialog.setSize(200, 200);
    dialog.setVisible(true);
}

From source file:GlassExample.java

/** Construct a Splash screen with the given image */
public static void main(String[] args) {
    JFrame f = new JFrame("GlassPane");

    final JPanel p1 = new JPanel();
    p1.add(new JLabel("GlassPane Example"));
    JButton show = new JButton("Show");
    p1.add(show);/*  w  w  w .  jav a  2  s. c  o  m*/
    p1.add(new JButton("No-op"));
    f.getContentPane().add(p1);

    final JPanel glass = (JPanel) f.getGlassPane();

    glass.setVisible(true);
    glass.setLayout(new GridBagLayout());
    JButton glassButton = new JButton("Hide");
    glass.add(glassButton);

    f.setSize(150, 80);
    f.setVisible(true);

    boolean debug = false;
    if (debug) {
        System.out.println("Button is " + glassButton);
        System.out.println("GlassPane is " + glass);
    }

    // Add actions to the buttons...

    // show button (re-)shows the glass pane.
    show.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            glass.setVisible(true);
            p1.repaint();
        }
    });
    // hide button hides the Glass Pane to show what's under.
    glassButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            glass.setVisible(false);
            p1.repaint();
        }
    });
}

From source file:Main.java

public static void setupNowLoadingPanel(JPanel panel) {
    JLabel loading = new JLabel("Loading...", SwingConstants.CENTER);
    panel.setLayout(new BorderLayout());
    panel.add(loading, BorderLayout.CENTER);
    panel.revalidate();//w ww  .j  a  v a 2s .  c  om
    panel.repaint();
}

From source file:ventanas.Reportes.java

public static void crearPieChart(DefaultPieDataset pData, JPanel jgra, String titulo) {
    JFreeChart grafica;/*from ww  w .  ja va2s .  c  o  m*/
    grafica = ChartFactory.createPieChart3D(titulo, pData, true, true, true);
    ChartPanel panel = new ChartPanel(grafica);
    jgra.removeAll();
    jgra.add(panel, BorderLayout.CENTER);
    jgra.repaint();
}

From source file:ventanas.Reportes.java

public static void crearBarChart(DefaultCategoryDataset data, JPanel jgra, String titulo, String titulox,
        String tituloy) {//from   ww w  .  j a  v  a  2s  .c o  m
    JFreeChart grafica;
    grafica = ChartFactory.createBarChart(titulo, titulox, tituloy, data, PlotOrientation.VERTICAL, true, true,
            true);
    ChartPanel cPanel = new ChartPanel(grafica);
    jgra.removeAll();
    jgra.repaint();
    jgra.add(cPanel, BorderLayout.CENTER);
    jgra.repaint();
}