Example usage for javax.swing JPanel add

List of usage examples for javax.swing JPanel add

Introduction

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

Prototype

public Component add(String name, Component comp) 

Source Link

Document

Adds the specified component to this container.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new BorderLayout());
    JPanel panel2 = new JPanel(new BorderLayout());
    panel2.add(new JButton("NORTH"), BorderLayout.NORTH);
    panel2.add(new JButton("CENTER"));
    panel.add(panel2);/*from  www  .j a  va  2s.  com*/
    panel.add(new JButton("SOUTH"), BorderLayout.SOUTH);
    panel.add(new JButton("EAST"), BorderLayout.EAST);
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    final BufferedImage image = ImageIO.read(url);
    int x = 50;/*w  w w  .  j av a  2  s. c om*/
    final Image crop = image.getSubimage(x, 0, image.getWidth() - x, image.getHeight());
    Runnable r = new Runnable() {
        @Override
        public void run() {
            JPanel gui = new JPanel();
            gui.add(new JLabel(new ImageIcon(image)), BorderLayout.LINE_START);
            gui.add(new JLabel("java2s.com"));
            gui.add(new JLabel(new ImageIcon(crop)), BorderLayout.LINE_END);
            JOptionPane.showMessageDialog(null, gui);
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:Main.java

public static void main(String[] args) {
    int nb = 4;// w w  w . ja v  a2  s. c  o  m
    final int frameCount = nb;

    for (int i = 0; i < frameCount; i++) {
        JFrame frame = new JFrame("Frame number " + i);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        JPanel p = new JPanel(new BorderLayout());
        p.add(new JLabel("Click on the corner to close..."), BorderLayout.CENTER);
        frame.setContentPane(p);
        frame.setSize(200, 200);
        frame.setLocation(100 + 20 * i, 100 + 20 * i);
        frame.setVisible(true);
    }
}

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("JSpinner Dates");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SpinnerModel model1 = new SpinnerDateModel();
    JSpinner spinner1 = new JSpinner(model1);
    JLabel label1 = new JLabel("All");
    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(label1, BorderLayout.WEST);
    panel1.add(spinner1, BorderLayout.CENTER);
    frame.add(panel1, BorderLayout.NORTH);

    frame.setSize(200, 90);//from   www .j  ava 2s .c o m
    frame.setVisible(true);

}

From source file:SpinnerNumberEditorSample1.java

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

    SpinnerModel model = new SpinnerNumberModel(50, 0, 100, .25);
    JSpinner spinner = new JSpinner(model);
    JComponent editor = new JSpinner.NumberEditor(spinner);
    spinner.setEditor(editor);//  ww  w  . jav  a2 s.  co  m

    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(spinner, BorderLayout.CENTER);
    frame.add(panel1, BorderLayout.SOUTH);

    frame.setSize(200, 90);
    frame.setVisible(true);
}

From source file:SpinnerDateEditorSample.java

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

    SpinnerModel model = new SpinnerDateModel();
    JSpinner spinner = new JSpinner(model);
    JComponent editor = new JSpinner.DateEditor(spinner, "MMMM yyyy");
    spinner.setEditor(editor);/*  w w w  .  ja  v a2s .  co  m*/

    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(spinner, BorderLayout.CENTER);
    frame.add(panel1, BorderLayout.SOUTH);

    frame.setSize(200, 90);
    frame.setVisible(true);
}

From source file:SpinnerDateSample.java

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

    SpinnerModel model1 = new SpinnerDateModel();
    JSpinner spinner1 = new JSpinner(model1);

    JLabel label1 = new JLabel("Dates/Date");
    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(label1, BorderLayout.WEST);
    panel1.add(spinner1, BorderLayout.CENTER);
    frame.add(panel1, BorderLayout.CENTER);

    frame.setSize(200, 90);/*from   www.  j av  a2 s  .com*/
    frame.setVisible(true);
}

From source file:SpinnerNumberSample.java

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

    SpinnerModel model1 = new SpinnerNumberModel();
    JSpinner spinner1 = new JSpinner(model1);

    JLabel label1 = new JLabel("Numbers");
    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(label1, BorderLayout.WEST);
    panel1.add(spinner1, BorderLayout.CENTER);
    frame.add(panel1, BorderLayout.SOUTH);

    frame.setSize(200, 90);//from   www . ja v a  2  s . c o m
    frame.setVisible(true);
}

From source file:SpinnerNumberEditorSample2.java

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

    SpinnerModel model = new SpinnerNumberModel(50, 0, 100, .25);
    JSpinner spinner = new JSpinner(model);
    JComponent editor = new JSpinner.NumberEditor(spinner, "#,##0.###");
    spinner.setEditor(editor);/*w  ww  .  j  ava  2  s  . c om*/

    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(spinner, BorderLayout.CENTER);
    frame.add(panel1, BorderLayout.SOUTH);

    frame.setSize(200, 90);
    frame.setVisible(true);
}

From source file:SpinnerDateEditorSample1.java

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

    SpinnerModel model = new SpinnerDateModel();
    JSpinner spinner = new JSpinner(model);
    JComponent editor = new JSpinner.DateEditor(spinner);
    spinner.setEditor(editor);//w  w w .  j a  v  a2s  .c  om

    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(spinner, BorderLayout.CENTER);
    frame.add(panel1, BorderLayout.SOUTH);

    frame.setSize(200, 90);
    frame.setVisible(true);
}