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

public Main() {
    Container pane = getContentPane();
    GroupLayout gl = new GroupLayout(pane);
    pane.setLayout(gl);

    JLabel avLbl = new JLabel("Available");
    JLabel tagsLbl = new JLabel("Tags");
    JLabel selLbl = new JLabel("Selected");

    JButton newBtn = new JButton("New");
    JButton moveBtn = new JButton(">>");
    JButton remBtn = new JButton("Remove");

    JList leftList = new JList();
    JScrollPane spleft = new JScrollPane(leftList);
    JList rightList = new JList();
    JScrollPane spright = new JScrollPane(rightList);

    gl.setAutoCreateGaps(true);//from w w w  . j a  va  2 s .  co m
    gl.setAutoCreateContainerGaps(true);

    gl.setHorizontalGroup(gl.createParallelGroup(CENTER).addComponent(tagsLbl)
            .addGroup(gl.createSequentialGroup()
                    .addGroup(gl.createParallelGroup(CENTER).addComponent(avLbl)
                            .addComponent(spleft, 100, 200, Short.MAX_VALUE).addComponent(newBtn))
                    .addComponent(moveBtn).addGroup(gl.createParallelGroup(CENTER).addComponent(selLbl)
                            .addComponent(spright, 100, 200, Short.MAX_VALUE).addComponent(remBtn))));
    gl.setVerticalGroup(gl.createSequentialGroup().addComponent(tagsLbl)
            .addGroup(gl.createParallelGroup(CENTER)
                    .addGroup(gl.createSequentialGroup().addComponent(avLbl)
                            .addComponent(spleft, 100, 250, Short.MAX_VALUE).addComponent(newBtn))
                    .addComponent(moveBtn).addGroup(gl.createSequentialGroup().addComponent(selLbl)
                            .addComponent(spright, 100, 250, Short.MAX_VALUE).addComponent(remBtn))));
    pack();
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:List.java

public void init() {
    Container cp = getContentPane();
    t.setEditable(false);/*  w  w  w  .  j av  a2s .com*/
    cp.setLayout(new FlowLayout());
    // Create Borders for components:
    Border brd = BorderFactory.createMatteBorder(1, 1, 2, 2, Color.BLACK);
    lst.setBorder(brd);
    t.setBorder(brd);
    // Add the first four items to the List
    for (int i = 0; i < 4; i++)
        lItems.addElement(flavors[count++]);
    // Add items to the Content Pane for Display
    cp.add(t);
    cp.add(lst);
    cp.add(b);
    // Register event listeners
    lst.addListSelectionListener(ll);
    b.addActionListener(bl);
}

From source file:TrackEvent.java

public void init() {
    Container c = getContentPane();
    c.setLayout(new GridLayout(event.length + 1, 2));
    for (int i = 0; i < event.length; i++) {
        JTextField t = new JTextField();
        t.setEditable(false);//  w  ww  . j av  a 2 s.  c om
        c.add(new JLabel(event[i], JLabel.RIGHT));
        c.add(t);
        h.put(event[i], t);
    }
    c.add(b1);
    c.add(b2);
}

From source file:DialogSeparator.java

public FlightReservation() {
    super("Dialog ");

    Container c = getContentPane();
    c.setLayout(new FlowLayout());
    c.add(new DialogSeparator("Options"));

    ButtonGroup group = new ButtonGroup();
    JRadioButton r1 = new JRadioButton("First class");
    group.add(r1);/*from  w w w .ja v a 2  s  . co  m*/
    c.add(r1);

    JRadioButton r2 = new JRadioButton("Business");
    group.add(r2);
    c.add(r2);

    JRadioButton r3 = new JRadioButton("Coach");
    group.add(r3);
    c.add(r3);

    c.add(new DialogSeparator());

    JButton b3 = new JButton("Exit");
    c.add(b3);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);

    setSize(300, 200);
    setVisible(true);
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container pane = getContentPane();
    GroupLayout gl = new GroupLayout(pane);
    pane.setLayout(gl);

    gl.setAutoCreateGaps(true);/* w w w.  jav  a  2  s . co m*/
    gl.setAutoCreateContainerGaps(true);

    JButton btn = new JButton("Switch");
    btn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 1; i < 9; i++) {
                labels[i].setVisible(!labels[i].isVisible());
            }
        }
    });

    gl.setHonorsVisibility(false);

    SequentialGroup seqGroup = gl.createSequentialGroup();
    gl.setHorizontalGroup(seqGroup);
    seqGroup.addComponent(btn);
    seqGroup.addPreferredGap(ComponentPlacement.UNRELATED, 10, 10);
    for (int i = 0; i < 10; i++) {
        seqGroup.addComponent(labels[i]);
        seqGroup.addPreferredGap(ComponentPlacement.UNRELATED, 10, 10);
    }
    ParallelGroup parGroup = gl.createParallelGroup();
    gl.setVerticalGroup(parGroup);
    parGroup.addComponent(btn);

    for (int i = 0; i < 10; i++) {
        parGroup.addComponent(labels[i]);
    }
    pack();
}

From source file:com.db2eshop.gui.dialog.BookingDialog.java

/** {@inheritDoc} */
@Override//from   w  w w . jav a  2  s.c  o  m
public void afterPropertiesSet() throws Exception {
    this.setTitle(title);

    this.getContentPane().removeAll();
    Container container = this.getContentPane();
    container.setLayout(new MigLayout("fill"));
    scrollPane = new JScrollPane(bookingTable);
    container.add(scrollPane, "grow, push");
}

From source file:SimpleFileChooser.java

public SimpleFileChooser() {
    super("File Chooser Test Frame");
    setSize(350, 200);/*from w w w  . j  av a  2  s .  com*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

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

    JButton openButton = new JButton("Open");
    JButton saveButton = new JButton("Save");
    JButton dirButton = new JButton("Pick Dir");
    final JLabel statusbar = new JLabel("Output of your selection will go here");

    // Create a file chooser that opens up as an Open dialog
    openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser();
            chooser.setMultiSelectionEnabled(true);
            int option = chooser.showOpenDialog(SimpleFileChooser.this);
            if (option == JFileChooser.APPROVE_OPTION) {
                File[] sf = chooser.getSelectedFiles();
                String filelist = "nothing";
                if (sf.length > 0)
                    filelist = sf[0].getName();
                for (int i = 1; i < sf.length; i++) {
                    filelist += ", " + sf[i].getName();
                }
                statusbar.setText("You chose " + filelist);
            } else {
                statusbar.setText("You canceled.");
            }
        }
    });

    // Create a file chooser that opens up as a Save dialog
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser();
            int option = chooser.showSaveDialog(SimpleFileChooser.this);
            if (option == JFileChooser.APPROVE_OPTION) {
                statusbar.setText("You saved "
                        + ((chooser.getSelectedFile() != null) ? chooser.getSelectedFile().getName()
                                : "nothing"));
            } else {
                statusbar.setText("You canceled.");
            }
        }
    });

    // Create a file chooser that allows you to pick a directory
    // rather than a file
    dirButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int option = chooser.showOpenDialog(SimpleFileChooser.this);
            if (option == JFileChooser.APPROVE_OPTION) {
                statusbar.setText("You opened "
                        + ((chooser.getSelectedFile() != null) ? chooser.getSelectedFile().getName()
                                : "nothing"));
            } else {
                statusbar.setText("You canceled.");
            }
        }
    });

    c.add(openButton);
    c.add(saveButton);
    c.add(dirButton);
    c.add(statusbar);
}

From source file:de.mpicbg.knime.hcs.core.view.OverlayLegendDialog.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Open Source Project license - Sphinx-4 (cmusphinx.sourceforge.net/sphinx4/)
    scrollPane1 = new JScrollPane();
    legendContainer = new JPanel();

    //======== this ========
    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    //======== scrollPane1 ========
    {/*from  w  w w .ja va2  s .  c  o m*/

        //======== legendContainer ========
        {
            legendContainer.setLayout(new GridLayout(0, 1));
        }
        scrollPane1.setViewportView(legendContainer);
    }
    contentPane.add(scrollPane1, BorderLayout.CENTER);
    pack();
    setLocationRelativeTo(getOwner());
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}

From source file:FontDialog.java

public FontDialog() {
    setTitle("FontDialog");
    setSize(600, 200);/*from  www.  j a v a2  s . c o m*/
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    Container contentPane = getContentPane();
    GridBagLayout gbl = new GridBagLayout();
    contentPane.setLayout(gbl);

    style.setSelectedIndex(0);

    JLabel label = new JLabel("Size: ");

    sample.setEditable(false);

    getContentPane().add(new JScrollPane(style));
    getContentPane().add(bold);
    getContentPane().add(italic);
    getContentPane().add(label);
    getContentPane().add(size);
    getContentPane().add(sample);
    sample.setText("The quick brown fox");

    bold.addActionListener(this);
    italic.addActionListener(this);
    style.addListSelectionListener(this);
    size.addActionListener(this);
}

From source file:GenderEditor.java

public TableCellEditorJComboBox() {
    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.setCellEditor(new GenderEditor());
    JScrollPane jsp = new JScrollPane(table);
    pane.add(jsp, BorderLayout.CENTER);
}