Example usage for javax.swing JFrame setLayout

List of usage examples for javax.swing JFrame setLayout

Introduction

In this page you can find the example usage for javax.swing JFrame setLayout.

Prototype

public void setLayout(LayoutManager manager) 

Source Link

Document

Sets the LayoutManager.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setLayout(new BorderLayout());
    JLabel label = new JLabel("<html>" + "<img src=\"" + Main.class.getResource("/resource/path/to/image1.jpg")
            + "\">" + "<img src=\"" + Main.class.getResource("/resource/path/to/image2.jpg") + "\">"
            + "The text</html>");
    frame.add(label, BorderLayout.CENTER);
    frame.setBounds(100, 100, 200, 100);
    frame.setVisible(true);// ww  w. j a  v a  2s  . c o m
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    String[] selections = { "green", "red", "orange", "dark blue" };
    JList list = new JList(selections);
    list.setSelectedIndex(1);/*w  w  w .java  2  s .  co m*/
    System.out.println(list.getSelectedValue());
    frame.add(new JScrollPane(list));
    frame.pack();

    frame.setVisible(true);
}

From source file:Absolute.java

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

    JButton ok = new JButton("OK");
    ok.setBounds(50, 150, 80, 25);//w w w. ja v a 2s .c  o m

    JButton close = new JButton("Close");
    close.setBounds(150, 150, 80, 25);

    f.add(ok);
    f.add(close);

    f.setSize(300, 250);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("Label Demo");
    f.setLayout(new FlowLayout());
    f.setSize(300, 200);// w w w  .j  a  v a2s .c o  m
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel label = new JLabel("java2s.com");
    f.add(label);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String avg[]) throws Exception {
    BufferedImage img = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    ImageIcon icon = new ImageIcon(img);
    JFrame frame = new JFrame();
    frame.setLayout(new FlowLayout());
    frame.setSize(200, 300);/* ww w.j  a va 2 s .  c o  m*/
    JLabel lbl = new JLabel();
    lbl.setIcon(icon);
    frame.add(lbl);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String[] argv) {
    JFrame f = new JFrame();
    f.setLayout(new BorderLayout());

    JPanel panel = new JPanel();
    JButton button = new JButton("A-ha!");
    button.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    panel.add(Box.createVerticalGlue());
    panel.add(button);// w  ww .  jav  a  2  s  . com
    panel.add(Box.createVerticalGlue());

    f.getContentPane().add(panel);

    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("Label Demo");
    f.setLayout(new FlowLayout());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel label = new JLabel("java2s.com");
    label.setEnabled(false);//  w  w w.  j av a 2s. c  o m

    f.add(label);
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    UIManager.put("ProgressBar.repaintInterval", 100);
    UIManager.put("ProgressBar.border", BorderFactory.createLineBorder(Color.blue, 2));
    JFrame f = new JFrame();
    f.setLayout(new GridLayout(0, 1, 5, 5));
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(createBar());/*from ww  w.j  a  va  2 s  . c o  m*/
    f.add(createBar());
    f.add(createBar());
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("Label Demo");
    f.setLayout(new FlowLayout());
    f.setSize(200, 360);/*  w w  w.jav a2 s .c  om*/
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel label = new JLabel("A default label");
    Border border = BorderFactory.createLineBorder(Color.BLACK);
    label.setBorder(border);
    f.add(label);

    f.setVisible(true);
}

From source file:Main.java

public static void main(String arg[]) {
    JFrame frame = new JFrame();
    frame.setLayout(new BorderLayout());

    JPanel gb = new JPanel(new GridBagLayout());
    JLabel content = new JLabel("Some text");

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.NORTH;
    gbc.weighty = 1;/*from   w w  w . j a  v a2  s . co m*/

    gb.add(content, gbc); // gbc is containing the GridBagConstraints
    frame.add(gb, BorderLayout.CENTER);

    frame.setVisible(true);
}