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

public static void main(String args[]) {
    JFrame frame = new JFrame("Active Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    UIManager.put(LABEL_FACTORY, new ActiveLabel());

    final JPanel panel = new JPanel();

    JButton button = new JButton("Get");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JLabel label = (JLabel) UIManager.get(LABEL_FACTORY);
            panel.add(label);//from   ww w  .  ja v a2s.co  m
            panel.revalidate();
        }
    };
    button.addActionListener(actionListener);

    frame.add(panel, BorderLayout.CENTER);
    frame.add(button, BorderLayout.SOUTH);
    frame.setSize(200, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Active Example");
    UIManager.put("LabelFactory", new ActiveLabel());
    final JPanel panel = new JPanel();
    JButton button = new JButton("Get");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JLabel label = (JLabel) UIManager.get("LabelFactory");
            panel.add(label);/*from   ww w  . ja  v a  2  s  .  c  o  m*/
            panel.revalidate();
        }
    };
    button.addActionListener(actionListener);

    Container contentPane = frame.getContentPane();
    contentPane.add(panel, BorderLayout.CENTER);
    contentPane.add(button, BorderLayout.SOUTH);
    frame.setSize(200, 200);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    final String LABEL_FACTORY = "LabelFactory";

    JFrame frame = new JFrame("Active Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    UIManager.put(LABEL_FACTORY, new ActiveLabel());

    final JPanel panel = new JPanel();

    JButton button = new JButton("Get");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JLabel label = (JLabel) UIManager.get(LABEL_FACTORY);
            panel.add(label);//from   ww  w  .j  a va 2 s.c o m
            panel.revalidate();
        }
    };
    button.addActionListener(actionListener);

    frame.add(panel, BorderLayout.CENTER);
    frame.add(button, BorderLayout.SOUTH);
    frame.setSize(200, 200);
    frame.setVisible(true);
}

From source file:ActiveSample.java

public static void main(String args[]) {

    JFrame frame = new JFrame("Active Example");

    UIManager.put(LABEL_FACTORY, new ActiveLabel());

    final JPanel panel = new JPanel();

    JButton button = new JButton("Get");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JLabel label = (JLabel) UIManager.get(LABEL_FACTORY);
            panel.add(label);//from  ww w .j  ava2s  .  c om
            panel.revalidate();
        }
    };
    button.addActionListener(actionListener);

    Container contentPane = frame.getContentPane();
    contentPane.add(panel, BorderLayout.CENTER);
    contentPane.add(button, BorderLayout.SOUTH);
    frame.setSize(200, 200);
    frame.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);//  w  ww  . j  av a2s  .  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) throws UnsupportedEncodingException {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new BorderLayout());
    JPanel buttons = new JPanel();
    JScrollPane pane = new JScrollPane(buttons);
    pane.getViewport().addChangeListener(e -> {
        System.out.println("Change in " + e.getSource());
        System.out.println("Vertical visible? " + pane.getVerticalScrollBar().isVisible());
        System.out.println("Horizontal visible? " + pane.getHorizontalScrollBar().isVisible());
    });//from   w ww  . ja  va 2 s.  com
    panel.add(pane);
    frame.setContentPane(panel);
    frame.setSize(300, 200);
    frame.setVisible(true);
    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
            for (int i = 0; i < 10; i++) {
                Thread.sleep(800);
                buttons.add(new JButton("Hello " + i));
                buttons.revalidate();
            }
            return null;
        }
    };
    worker.execute();
}

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();
        gui.repaint();/*from w  ww  .j  av a  2 s . c  om*/
    });

    JOptionPane jOptionPane = new JOptionPane(gui);

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

From source file:Main.java

public static void main(String[] args) {
    JPanel topPanel = new JPanel();
    topPanel.setPreferredSize(new Dimension(200, 200));
    topPanel.setBackground(Color.WHITE);

    JTextArea chatArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(chatArea);

    JPanel mainPanel = new JPanel(new BorderLayout(5, 5));
    mainPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    mainPanel.add(topPanel, BorderLayout.CENTER);
    mainPanel.add(scrollPane, BorderLayout.SOUTH);

    chatArea.getDocument().addDocumentListener(new DocumentListener() {

        @Override//  w  w w  .  j a va  2s  .  c  om
        public void insertUpdate(DocumentEvent e) {
            updateLineCount();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateLineCount();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateLineCount();
        }

        private void updateLineCount() {
            int lineCount = chatArea.getLineCount();
            if (lineCount <= 4) {
                chatArea.setRows(lineCount);
                mainPanel.revalidate();
            }
        }
    });

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(mainPanel);
    f.pack();
    f.setVisible(true);
}

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();
    panel.repaint();//from  w  w  w  .j  a va 2  s.c  o m
}

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  .  ja v a2 s  .c  om
        main.revalidate();
        main.repaint();

    }

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