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

/**
 * Aligns the first <code>rows</code> * <code>cols</code> components of <code>parent</code> in a grid. Each
 * component in a column is as wide as the maximum preferred width of the components in that column; height is
 * similarly determined for each row. The parent is made just big enough to fit them all.
 * /*from   ww w .j ava 2 s .  c  o  m*/
 * @param parent
 * 
 * @param rows
 *            number of rows
 * @param cols
 *            number of columns
 * @param initialX
 *            x location to start the grid at
 * @param initialY
 *            y location to start the grid at
 * @param xPad
 *            x padding between cells
 * @param yPad
 *            y padding between cells
 */
private static void makeSpringCompactGrid(Container parent, int rows, int cols, int initialX, int initialY,
        int xPad, int yPad) {

    SpringLayout layout = new SpringLayout();
    parent.setLayout(layout);

    // Align all cells in each column and make them the same width.
    Spring x = Spring.constant(initialX);
    for (int c = 0; c < cols; c++) {
        Spring width = Spring.constant(0);
        for (int r = 0; r < rows; r++) {
            width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth());
        }
        for (int r = 0; r < rows; r++) {
            SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
            constraints.setX(x);
            constraints.setWidth(width);
        }
        x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
    }

    // Align all cells in each row and make them the same height.
    Spring y = Spring.constant(initialY);
    for (int r = 0; r < rows; r++) {
        Spring height = Spring.constant(0);
        for (int c = 0; c < cols; c++) {
            height = Spring.max(height, getConstraintsForCell(r, c, parent, cols).getHeight());
        }
        for (int c = 0; c < cols; c++) {
            SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
            constraints.setY(y);
            constraints.setHeight(height);
        }
        y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
    }

    // Set the parent's size.
    SpringLayout.Constraints pCons = layout.getConstraints(parent);
    pCons.setConstraint(SpringLayout.SOUTH, y);
    pCons.setConstraint(SpringLayout.EAST, x);
}

From source file:ch.descabato.browser.BackupBrowser.java

public static void main2(final String[] args)
        throws InterruptedException, InvocationTargetException, SecurityException, IOException {
    if (args.length > 1)
        throw new IllegalArgumentException(
                "SYNTAX:  java... " + BackupBrowser.class.getName() + " [initialPath]");

    SwingUtilities.invokeAndWait(new Runnable() {

        @Override/*from ww  w  .ja  v  a 2  s  . co  m*/
        public void run() {
            tryLoadSubstanceLookAndFeel();
            final JFrame f = new JFrame("OtrosVfsBrowser demo");
            f.addWindowListener(finishedListener);
            Container contentPane = f.getContentPane();
            contentPane.setLayout(new BorderLayout());
            DataConfiguration dc = null;
            final PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
            File favoritesFile = new File("favorites.properties");
            propertiesConfiguration.setFile(favoritesFile);
            if (favoritesFile.exists()) {
                try {
                    propertiesConfiguration.load();
                } catch (ConfigurationException e) {
                    e.printStackTrace();
                }
            }
            dc = new DataConfiguration(propertiesConfiguration);
            propertiesConfiguration.setAutoSave(true);
            final VfsBrowser comp = new VfsBrowser(dc, (args.length > 0) ? args[0] : null);
            comp.setSelectionMode(SelectionMode.FILES_ONLY);
            comp.setMultiSelectionEnabled(true);
            comp.setApproveAction(new AbstractAction(Messages.getMessage("demo.showContentButton")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    FileObject[] selectedFiles = comp.getSelectedFiles();
                    System.out.println("Selected files count=" + selectedFiles.length);
                    for (FileObject selectedFile : selectedFiles) {
                        try {
                            FileSize fileSize = new FileSize(selectedFile.getContent().getSize());
                            System.out.println(selectedFile.getName().getURI() + ": " + fileSize.toString());
                            Desktop.getDesktop()
                                    .open(new File(new URI(selectedFile.getURL().toExternalForm())));
                            //                byte[] bytes = readBytes(selectedFile.getContent().getInputStream(), 150 * 1024l);
                            //                JScrollPane sp = new JScrollPane(new JTextArea(new String(bytes)));
                            //                JDialog d = new JDialog(f);
                            //                d.setTitle("Content of file: " + selectedFile.getName().getFriendlyURI());
                            //                d.getContentPane().add(sp);
                            //                d.setSize(600, 400);
                            //                d.setVisible(true);
                        } catch (Exception e1) {
                            LOGGER.error("Failed to read file", e1);
                            JOptionPane.showMessageDialog(f,
                                    (e1.getMessage() == null) ? e1.toString() : e1.getMessage(), "Error",
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
            });

            comp.setCancelAction(new AbstractAction(Messages.getMessage("general.cancelButtonText")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    f.dispose();
                    try {
                        propertiesConfiguration.save();
                    } catch (ConfigurationException e1) {
                        e1.printStackTrace();
                    }
                    System.exit(0);
                }
            });
            contentPane.add(comp);

            f.pack();
            f.setVisible(true);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        }
    });
    while (!finished)
        Thread.sleep(100);
}

From source file:edu.mbl.jif.datasetconvert.CheckboxTreeDimensions.java

public static void test() {
    JSONObject sumMD = SumMetadata.newSummaryMetadata("", "", new ImageAttributes(100, 100),
            new String[] { "Aniso", "Orient", "Sample0", "Sample1" }, 5, 10, 1, "source", "comment");
    final CheckboxTreeDimensions tree = new CheckboxTreeDimensions(sumMD);
    QuickFrame f = new QuickFrame("Test");

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(300, 600);//from w ww.jav  a2  s . co  m
    Container jContentPane = new JPanel();
    jContentPane.setLayout(new BorderLayout());
    JScrollPane cbt = tree.getCheckboxTree();
    cbt.setPreferredSize(new Dimension(200, 400));
    jContentPane.add(cbt, BorderLayout.CENTER);

    JButton buttonTest = new JButton("test");
    buttonTest.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tree.getSelectedIndices();
        }
    });
    jContentPane.add(buttonTest, BorderLayout.SOUTH);
    f.setContentPane(jContentPane);
    f.setTitle("CheckboxTree");
    f.pack();
    f.setVisible(true);

}

From source file:TableDemoApplet.java

private static void createGUI(Container contentPane) {
    Object[][] rowData = new String[][] { { "98-43", "AraAra! SL" }, { "81-31", "Aragones Transports SA" },
            { "12-72", "Rocca SL" }, { "99-10", "Rodriguez e Hijos SA" }, { "00-65", "Rimbau Motors SL" } };
    JTable table = new JTable(rowData, new String[] { "Part No", "Provider" });

    JComboBox companyComboBox = new JComboBox(new Object[] { "AraAra! SL", "Aragones Transports SA", "Rocca SL",
            "Rodriguez e Hijos SA", "Rimbau Motors SL" });
    companyComboBox.setEditable(true);//from ww w . j  a v a  2  s. c  om
    new S15WorkingBackspace(companyComboBox);

    // setup the ComboBoxCellEditor, DefaultCellEditor won't work!
    table.getColumnModel().getColumn(1).setCellEditor(new ComboBoxCellEditor(companyComboBox));

    table.setPreferredScrollableViewportSize(new Dimension(400, 100));
    JScrollPane scrollPane = new JScrollPane(table);

    contentPane.setLayout(new java.awt.FlowLayout());
    contentPane.add(scrollPane);
    contentPane.add(new JTextField("HALLO!"));
}

From source file:GridTest.java

public GridTest(int rows, int cols) {
    Container pane = getContentPane();
    pane.setLayout(new GridLayout(rows, cols));
    for (int i = 0; i < 20; i++) {
        JButton button = new JButton(Integer.toString(i + 1));
        pane.add(button);//from w  w  w .j a v a2  s .c  o m
    }
}

From source file:Main.java

public Test() {
    setSize(500, 210);//w w w. j a va 2 s.co m
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTable tabell = new JTable(cells, name);

    Container c = getContentPane();
    c.setLayout(new FlowLayout());
    c.add(new JScrollPane(tabell), BorderLayout.CENTER);
}

From source file:FlowLayout1.java

public void init() {
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    for (int i = 0; i < 20; i++)
        cp.add(new JButton("Button " + i));
}

From source file:FlowLayoutBehaviour.java

public FlowLayoutBehaviour() {
    super();//ww w  .  ja  va 2s .  c om
    Container pane = getContentPane();
    pane.setLayout(new FlowLayout(FlowLayout.LEFT));
    pane.add(new JLabel("This is a test"));
    pane.add(new JButton("of a FlowLayout"));
    pane.add(new JTextField(30));
    pane.add(new JTextArea("This is a JTextArea", 3, 10));
    pane.add(new JLabel("This is a FlowLayout test with a long string"));
}

From source file:Main.java

public Main() {
    super();/*from   ww  w.  j a v a2s  .c o m*/
    Container pane = getContentPane();
    pane.setLayout(new FlowLayout(FlowLayout.LEFT));
    pane.add(new JLabel("This is a test"));
    pane.add(new JButton("of a FlowLayout"));
    pane.add(new JTextField(30));
    pane.add(new JTextArea("This is a JTextArea", 3, 10));
    pane.add(new JLabel("This is a FlowLayout test with a long string"));
}

From source file:Button1.java

public void init() {
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(b1);
    cp.add(b2);
}