Example usage for java.awt Container setLayout

List of usage examples for java.awt Container setLayout

Introduction

In this page you can find the example usage for java.awt Container setLayout.

Prototype

public void setLayout(LayoutManager mgr) 

Source Link

Document

Sets the layout manager for this container.

Usage

From source file:JOptionDemo.java

JOptionDemo(String s) {
    super(s);/*  w w  w . jav a2s.  c o  m*/

    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());

    JButton b = new JButton("Give me a message");
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(JOptionDemo.this, "This is your message: etaoin shrdlu",
                    "Coded Message", JOptionPane.INFORMATION_MESSAGE);
        }
    });
    cp.add(b);

    b = new JButton("Goodbye!");
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    cp.add(b);

    // size the main window
    pack();
}

From source file:Main.java

public Main() {
    super("Demostrating BoxLayout");
    final int SIZE = 3;
    Container c = getContentPane();
    c.setLayout(new BorderLayout(30, 30));

    Box boxes[] = new Box[4];

    boxes[0] = Box.createHorizontalBox();
    boxes[1] = Box.createVerticalBox();
    boxes[2] = Box.createHorizontalBox();
    boxes[3] = Box.createVerticalBox();

    for (int i = 0; i < SIZE; i++)
        boxes[0].add(new JButton("boxes[0]: " + i));

    for (int i = 0; i < SIZE; i++) {
        boxes[1].add(Box.createVerticalStrut(25));
        boxes[1].add(new JButton("boxes[1]: " + i));
    }/* w  w w .j a v a2  s .co  m*/

    for (int i = 0; i < SIZE; i++) {
        boxes[2].add(Box.createHorizontalGlue());
        boxes[2].add(new JButton("boxes[2]: " + i));
    }

    for (int i = 0; i < SIZE; i++) {
        boxes[3].add(Box.createRigidArea(new Dimension(12, 8)));
        boxes[3].add(new JButton("boxes[3]: " + i));
    }

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    for (int i = 0; i < SIZE; i++) {
        panel.add(Box.createGlue());
        panel.add(new JButton("panel: " + i));
    }

    c.add(boxes[0], BorderLayout.NORTH);
    c.add(boxes[1], BorderLayout.EAST);
    c.add(boxes[2], BorderLayout.SOUTH);
    c.add(boxes[3], BorderLayout.WEST);
    c.add(panel, BorderLayout.CENTER);

    setSize(350, 300);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);

}

From source file:GenderRenderer.java

public TableCellRendererJComboBox() {
    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());
    TableValues tv = new TableValues();
    table = new JTable(tv);
    TableColumnModel tcm = table.getColumnModel();
    TableColumn tc = tcm.getColumn(TableValues.GENDER);
    tc.setCellRenderer(new GenderRenderer());
    JScrollPane jsp = new JScrollPane(table);
    pane.add(jsp, BorderLayout.CENTER);
}

From source file:Faces.java

public void init() {
    faces = new Icon[] { new ImageIcon(getClass().getResource("Face0.gif")),
            new ImageIcon(getClass().getResource("Face1.gif")),
            new ImageIcon(getClass().getResource("Face2.gif")),
            new ImageIcon(getClass().getResource("Face3.gif")),
            new ImageIcon(getClass().getResource("Face4.gif")), };
    jb = new JButton("JButton", faces[3]);
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    jb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (mad) {
                jb.setIcon(faces[3]);//from w  w w .j  av  a 2 s . com
                mad = false;
            } else {
                jb.setIcon(faces[0]);
                mad = true;
            }
            jb.setVerticalAlignment(JButton.TOP);
            jb.setHorizontalAlignment(JButton.LEFT);
        }
    });
    jb.setRolloverEnabled(true);
    jb.setRolloverIcon(faces[1]);
    jb.setPressedIcon(faces[2]);
    jb.setDisabledIcon(faces[4]);
    jb.setToolTipText("Yow!");
    cp.add(jb);
    jb2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (jb.isEnabled()) {
                jb.setEnabled(false);
                jb2.setText("Enable");
            } else {
                jb.setEnabled(true);
                jb2.setText("Disable");
            }
        }
    });
    cp.add(jb2);
}

From source file:SplashScreen.java

public SplashScreen(final BufferedImage img) {
    JPanel panel = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D) g.create();

            g2d.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), SplashScreen.this);
        }/*from  w  w  w.j  av a2s .c om*/
    };
    panel.setPreferredSize(new Dimension(img.getWidth(), img.getHeight()));

    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    content.add(panel, BorderLayout.NORTH);
    content.add(label = new JLabel(), BorderLayout.CENTER);
    content.add(bar = new JProgressBar(), BorderLayout.SOUTH);
    pack();
    setLocationRelativeTo(null);
}

From source file:JScrollPanes.java

public void init() {
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    // Create Borders for components:
    Border brd = BorderFactory.createMatteBorder(1, 1, 1, 1, Color.BLACK);
    t1.setBorder(brd);/*from w ww .  j a  va 2  s  .  c om*/
    t2.setBorder(brd);
    sp3.setBorder(brd);
    sp4.setBorder(brd);
    sp5.setBorder(brd);
    sp6.setBorder(brd);
    // Initialize listeners and add components:
    b1.addActionListener(new B1L());
    cp.add(b1);
    cp.add(t1);
    b2.addActionListener(new B2L());
    cp.add(b2);
    cp.add(t2);
    b3.addActionListener(new B3L());
    cp.add(b3);
    b4.addActionListener(new B4L());
    cp.add(b4);
    cp.add(sp3);
    cp.add(sp4);
    cp.add(sp5);
    cp.add(sp6);
}

From source file:BusinessLogic.java

public void init() {
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(t);//  w  ww. jav a 2s.  co m
    calc1.addActionListener(new Calc1L());
    calc2.addActionListener(new Calc2L());
    JPanel p1 = new JPanel();
    p1.add(calc1);
    p1.add(calc2);
    cp.add(p1);
    mod.getDocument().addDocumentListener(new ModL());
    JPanel p2 = new JPanel();
    p2.add(new JLabel("Modifier:"));
    p2.add(mod);
    cp.add(p2);
}

From source file:ExecDemoNS.java

/** Constructor - set up strings and things. */
public ExecDemoNS(String prog) {
    super("ExecDemo: " + prog);
    String osname = System.getProperty("os.name");
    if (osname == null)
        throw new IllegalArgumentException("no os.name");
    if (prog.equals("netscape"))
        program = // Windows or UNIX only for now, sorry Mac fans
                (osname.toLowerCase().indexOf("windows") != -1)
                        ? "c:/program files/netscape/communicator/program/netscape.exe"
                        : "/usr/local/netscape/netscape";
    else/*from  w  ww.  j a  v a2 s  .  c o  m*/
        program = prog;

    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    JButton b;
    cp.add(b = new JButton("Exec"));
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            runProg();
        }
    });
    cp.add(b = new JButton("Wait"));
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            doWait();
        }
    });
    cp.add(b = new JButton("Exit"));
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.exit(0);
        }
    });
    pack();
}

From source file:MyFilterChooser.java

public MyFilterChooser() {
    super("Filter Test Frame");
    setSize(350, 200);//from  w  ww .  java  2s .  co m
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new FlowLayout());

    JButton openButton = new JButton("Open");
    final JLabel statusbar = new JLabel("Output of your selection will go here");

    openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            String[] pics = new String[] { "gif", "jpg", "tif" };
            String[] audios = new String[] { "au", "aiff", "wav" };
            JFileChooser chooser = new JFileChooser();
            chooser.addChoosableFileFilter(new SimpleFileFilter(pics, "Images (*.gif, *.jpg, *.tif)"));
            chooser.addChoosableFileFilter(new SimpleFileFilter(".MOV"));
            chooser.addChoosableFileFilter(new SimpleFileFilter(audios, "Sounds (*.aiff, *.au, *.wav)"));
            int option = chooser.showOpenDialog(MyFilterChooser.this);
            if (option == JFileChooser.APPROVE_OPTION) {
                if (chooser.getSelectedFile() != null)
                    statusbar.setText("You chose " + chooser.getSelectedFile().getName());
            } else {
                statusbar.setText("You canceled.");
            }
        }
    });

    c.add(openButton);
    c.add(statusbar);
    setVisible(true);
}

From source file:SaveDialog.java

/** Construct the object including its GUI */
public SaveDialog() {
    super("SaveDialog");
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(new Label("Press this button to see the Quit dialog: "));
    cp.add(quitButton = new Button("Quit"));
    quitButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("In Exit Button's action handler");
            if (okToQuit()) {
                setVisible(false);/*from  ww  w.j a  v a2s  .c o m*/
                dispose();
                System.exit(0);
            }
        }
    });
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            setVisible(false);
            dispose();
            System.exit(0);
        }
    });

    pack();
}