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

public UndoableToggleApp() {

    // Create some toggle buttons (and subclasses)
    JToggleButton tog = new JToggleButton("ToggleButton");
    JCheckBox cb = new JCheckBox("CheckBox");
    JRadioButton radio = new JRadioButton("RadioButton");

    // Add our listener to each toggle button
    SimpleListener sl = new SimpleListener();
    tog.addActionListener(sl);//from w  w w.j a v  a  2  s.c  o m
    cb.addActionListener(sl);
    radio.addActionListener(sl);

    // Layout the buttons
    Box buttonBox = new Box(BoxLayout.Y_AXIS);
    buttonBox.add(tog);
    buttonBox.add(cb);
    buttonBox.add(radio);

    // Create undo and redo buttons (initially disabled)
    undoButton = new JButton("Undo");
    redoButton = new JButton("Redo");
    undoButton.setEnabled(false);
    redoButton.setEnabled(false);

    // Add a listener to the undo button. It attempts to call undo() on the
    // current edit, then enables/disables the undo/redo buttons as
    // appropriate.
    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.undo();
            } catch (CannotUndoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    // Add a redo listener: just like the undo listener, but for redo this
    // time.
    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.redo();
            } catch (CannotRedoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    // Layout the undo/redo buttons
    Box undoRedoBox = new Box(BoxLayout.X_AXIS);
    undoRedoBox.add(Box.createGlue());
    undoRedoBox.add(undoButton);
    undoRedoBox.add(Box.createHorizontalStrut(2));
    undoRedoBox.add(redoButton);
    undoRedoBox.add(Box.createGlue());

    // Layout the main frame
    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    content.add(buttonBox, BorderLayout.CENTER);
    content.add(undoRedoBox, BorderLayout.SOUTH);
    setSize(400, 150);
}

From source file:TestImage2.java

public TestImage2() {
    JFrame frame = new JFrame(getClass().getName());
    Container pane = frame.getContentPane();
    pane.setLayout(new BorderLayout());

    pane.add(this);

    image = toRenderedImage(/*  www. j a v  a  2  s  . c  o m*/
            new String[] { "-##########################################################################-",
                    "----------------------------------------------------------------------------",
                    "-##########################################################################-",
                    "----------------------------------------------------------------------------",
                    "-##########################################################################-",
                    "----------------------------------------------------------------------------",
                    "-##########################################################################-",
                    "----------------------------------------------------------------------------",
                    "-##########################################################################-",
                    "----------------------------------------------------------------------------",
                    "-##########################################################################-",
                    "----------------------------------------------------------------------------",
                    "----------------------------------------------------------------------------",
                    "----------------------------------------------------------------------------",
                    "----####---------------####---------------####---------------####-----------",
                    "--------##-----------------##-----------------##-----------------##---------",
                    "----------####---------------####---------------####---------------####-----",
                    "--------------#------------------#------------------#------------------#----",
                    "--------------#------------------#------------------#------------------#----",
                    "----------------------------------------------------------------------------",
                    "---#############------#############------#############------#############---",
                    "---#############------#############------#############------#############---",
                    "---#############------#############------#############------#############---",
                    "---#############------#############------#############------#############---",
                    "---#############------#############------#############------#############---",
                    "---#############------#############------#############------#############---",
                    "---#############------#############------#############------#############---",
                    "---#############------#############------#############------#############---",
                    "---#############------#############------#############------#############---",
                    "---#############------#############------#############------#############---",
                    "---#############------#############------#############------#############---",
                    "----------------------------------------------------------------------------",
                    "----------------------------------------------------------------------------",
                    "----####---------------####---------------####---------------####-----------",
                    "--------##-----------------##-----------------##-----------------##---------",
                    "----------####---------------####---------------####---------------####-----",
                    "--------------#------------------#------------------#------------------#----",
                    "--------------#------------------#------------------#------------------#----",
                    "----------------------------------------------------------------------------",
                    "---#############------#############------#############------#############---",
                    "---#############------#############------#############------#############---",
                    "----------------------------------------------------------------------------",
                    "----------------------------------------------------------------------------" });

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocation(100, 100);
    frame.pack();
    frame.setSize(200, 200);
    frame.setVisible(true);
}

From source file:UndoableToggleApp4.java

public UndoableToggleApp4() {
    SimpleListener sl = new SimpleListener();
    tog.addActionListener(sl);//from w w  w .ja va2  s . c o m
    cb.addActionListener(sl);
    radio.addActionListener(sl);

    Box buttonBox = new Box(BoxLayout.Y_AXIS);
    buttonBox.add(tog);
    buttonBox.add(cb);
    buttonBox.add(radio);

    startButton.setEnabled(true);
    endButton.setEnabled(false);
    undoButton.setEnabled(false);
    redoButton.setEnabled(false);

    startButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            edit = new StateEdit(UndoableToggleApp4.this);
            startButton.setEnabled(false);
            endButton.setEnabled(true);
            // undoButton.setEnabled(edit.canUndo());
            //
            // NOTE: We really don't want to be able to undo until end() is pressed,
            // but StateEdit does not enforce this for us!
            undoButton.setEnabled(false);
            redoButton.setEnabled(edit.canRedo());
        }
    });

    endButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            edit.end();
            startButton.setEnabled(true);
            endButton.setEnabled(false);
            undoButton.setEnabled(edit.canUndo());
            redoButton.setEnabled(edit.canRedo());
        }
    });

    // Add a listener to the undo button. It attempts to call undo() on the
    // current edit, then enables/disables the undo/redo buttons as appropriate.
    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.undo();
            } catch (CannotUndoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.redo();
            } catch (CannotRedoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    // Lay out the state/end and undo/redo buttons.
    Box undoRedoBox = new Box(BoxLayout.X_AXIS);
    undoRedoBox.add(Box.createGlue());
    undoRedoBox.add(startButton);
    undoRedoBox.add(Box.createHorizontalStrut(2));
    undoRedoBox.add(endButton);
    undoRedoBox.add(Box.createHorizontalStrut(2));
    undoRedoBox.add(undoButton);
    undoRedoBox.add(Box.createHorizontalStrut(2));
    undoRedoBox.add(redoButton);
    undoRedoBox.add(Box.createGlue());

    // Lay out the main frame.
    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    content.add(buttonBox, BorderLayout.CENTER);
    content.add(undoRedoBox, BorderLayout.SOUTH);
    setSize(400, 150);
}

From source file:CoordinatesDemo.java

private void buildUI(Container container) {
    container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));

    CoordinateArea coordinateArea = new CoordinateArea(this);
    container.add(coordinateArea);//from  w ww.  j  av a 2  s .  co  m

    label = new JLabel();
    resetLabel();
    container.add(label);

    //Align the left edges of the components.
    coordinateArea.setAlignmentX(Component.LEFT_ALIGNMENT);
    label.setAlignmentX(Component.LEFT_ALIGNMENT); //redundant
}

From source file:phex.gui.dialogs.UpdateNotificationDialog.java

private void prepareComponent() {
    CloseEventHandler closeEventHandler = new CloseEventHandler();
    addWindowListener(closeEventHandler);

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

    JPanel contentPanel = new JPanel();
    //JPanel contentPanel = new FormDebugPanel();
    contentPane.add(contentPanel, BorderLayout.CENTER);

    CellConstraints cc = new CellConstraints();
    FormLayout layout = new FormLayout("2dlu, fill:d:grow, 2dlu", // columns
            "p, p, 16dlu, fill:p:grow, 16dlu," + // rows
                    "p, 2dlu, p 4dlu"); //btn rows
    PanelBuilder contentPB = new PanelBuilder(layout, contentPanel);
    int columnCount = layout.getColumnCount();
    int rowCount = layout.getRowCount();

    DialogBanner banner = new DialogBanner(Localizer.getString("UpdateNotification_BannerHeader"),
            Localizer.getString("UpdateNotification_BannerSubHeader"));
    contentPB.add(banner, cc.xywh(1, 1, columnCount, 1));

    contentPB.add(new JSeparator(), cc.xywh(1, 2, columnCount, 1));

    JPanel notifyPanel = buildNotificationPanel();
    contentPB.add(notifyPanel, cc.xy(2, 4, "center, center"));

    contentPB.add(new JSeparator(), cc.xywh(1, rowCount - 3, columnCount, 1));

    JButton closeBtn = new JButton(Localizer.getString("Close"));
    closeBtn.addActionListener(closeEventHandler);
    JButton downloadBtn = new JButton(Localizer.getString("Download"));
    downloadBtn.setDefaultCapable(true);
    downloadBtn.setRequestFocusEnabled(true);
    downloadBtn.addActionListener(new DownloadBtnListener());
    JPanel btnPanel = ButtonBarFactory.buildOKCancelBar(downloadBtn, closeBtn);
    contentPB.add(btnPanel, cc.xywh(2, rowCount - 1, columnCount - 2, 1));

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    getRootPane().setDefaultButton(downloadBtn);

    pack();/*from   w w w.j a  va  2 s.  c  om*/
    setLocationRelativeTo(getParent());
}

From source file:SelectionDemo.java

private void buildUI(Container container, ImageIcon image) {
    container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));

    SelectionArea area = new SelectionArea(image, this);
    container.add(area);//  w w w .j  a  v  a 2  s .  com

    label = new JLabel("Drag within the image.");
    label.setLabelFor(area);
    container.add(label);

    //Align the left edges of the components.
    area.setAlignmentX(Component.LEFT_ALIGNMENT);
    label.setAlignmentX(Component.LEFT_ALIGNMENT); //redundant
}

From source file:ru.goodfil.catalog.ui.forms.DeployDatabaseWindow.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - Oleg V
    label1 = new JLabel();
    label2 = new JLabel();
    scrollPane1 = new JScrollPane();
    lstLogs = new JList();
    btnDeployDatabase = new JButton();
    CellConstraints cc = new CellConstraints();

    //======== this ========
    setTitle(//from   ww w. j a v  a2  s. co  m
            "\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0431\u0430\u0437\u044b \u043d\u0430 \u0441\u0430\u0439\u0442");
    setModal(true);
    Container contentPane = getContentPane();
    contentPane
            .setLayout(new FormLayout("default:grow", "2*(default, $lgap), fill:default:grow, $lgap, default"));

    //---- label1 ----
    label1.setText(
            "\u0421\u0435\u0439\u0447\u0430\u0441 \u0431\u0430\u0437\u0430 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u0430 \u043d\u0430 \u0441\u0430\u0439\u0442.");
    contentPane.add(label1, cc.xy(1, 1));

    //---- label2 ----
    label2.setText(
            "\u041e\u0431\u044b\u0447\u043d\u043e \u043d\u0430 \u044d\u0442\u043e \u0443\u0445\u043e\u0434\u0438\u0442 1-2 \u043c\u0438\u043d\u0443\u0442\u044b.");
    contentPane.add(label2, cc.xy(1, 3));

    //======== scrollPane1 ========
    {
        scrollPane1.setViewportView(lstLogs);
    }
    contentPane.add(scrollPane1, cc.xy(1, 5));

    //---- btnDeployDatabase ----
    btnDeployDatabase.setText(
            "\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0431\u0430\u0437\u0443 \u043d\u0430 \u0441\u0430\u0439\u0442");
    btnDeployDatabase.setFont(
            btnDeployDatabase.getFont().deriveFont(btnDeployDatabase.getFont().getStyle() | Font.BOLD));
    btnDeployDatabase.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            btnDeployDatabaseActionPerformed();
        }
    });
    contentPane.add(btnDeployDatabase, cc.xy(1, 7));
    pack();
    setLocationRelativeTo(getOwner());
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}

From source file:Main.java

public Main() {
    Container content = getContentPane();
    content.setLayout(new FlowLayout());
    JLabel jl = new JLabel("          Calculator                ");
    textField = new JTextField(15);
    num1 = new JButton(" 1 ");
    num2 = new JButton(" 2 ");
    num3 = new JButton(" 3 ");
    num4 = new JButton(" 4 ");
    num5 = new JButton(" 5 ");
    num6 = new JButton(" 6 ");
    num7 = new JButton(" 7 ");
    num8 = new JButton(" 8 ");
    num9 = new JButton(" 9 ");
    num0 = new JButton(" 0 ");
    add = new JButton(" + ");
    sub = new JButton("  -  ");
    div = new JButton("  / ");
    mult = new JButton(" *  ");
    equalto = new JButton(" = ");
    exit = new JButton("    Exit     ");
    point = new JButton("  . ");
    reset = new JButton("C");
    reset.setBackground(Color.RED);
    num1.addActionListener(this);
    num2.addActionListener(this);
    num3.addActionListener(this);
    num4.addActionListener(this);
    num5.addActionListener(this);
    num6.addActionListener(this);
    num7.addActionListener(this);
    num8.addActionListener(this);
    num9.addActionListener(this);
    num0.addActionListener(this);
    add.addActionListener(this);
    sub.addActionListener(this);
    mult.addActionListener(this);
    div.addActionListener(this);
    equalto.addActionListener(this);
    exit.addActionListener(this);
    point.addActionListener(this);
    reset.addActionListener(this);
    content.add(jl);//from  w  w  w. j a v a2s . c om
    content.add(textField);
    content.add(num1);
    content.add(num2);
    content.add(num3);
    content.add(add);
    content.add(num4);
    content.add(num5);
    content.add(num6);
    content.add(sub);
    content.add(num7);
    content.add(num8);
    content.add(num9);
    content.add(div);
    content.add(num0);
    content.add(point);
    content.add(mult);
    content.add(equalto);
    content.add(reset);
    content.add(exit);
}

From source file:org.sunzoft.sunstock.StockMain.java

protected void initGUI() {
    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(1024, 600);//from w  ww.  j a va 2  s  . com
    frame.setLocationRelativeTo(null);

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            // 
            Container contentPane = frame.getContentPane();
            contentPane.setLayout(new BorderLayout(0, 0));

            JFreeChart chart = createChart();
            // 6:chartPanel        
            chartPanel = new ChartPanel(chart);
            chartPanel.setMouseZoomable(true);
            contentPane.add(chartPanel, BorderLayout.CENTER);

            JPanel pCtrl = new JPanel();
            if (profits.size() > 0) {
                startInput.setText(profits.get(0).date);
                endInput.setText(profits.get(profits.size() - 1).date);
            } else {
                startInput.setText("20100101");
                endInput.setText("20100101");
            }
            pCtrl.add(new JLabel(""));
            pCtrl.add(startInput);
            pCtrl.add(new JLabel(""));
            pCtrl.add(endInput);
            JButton confirm = new JButton("");
            confirm.addActionListener(StockMain.this);
            pCtrl.add(confirm);
            contentPane.add(pCtrl, BorderLayout.NORTH);

            JPanel pStatus = new JPanel();
            statusLabel = new JLabel(getStatusText());
            pStatus.add(statusLabel);
            contentPane.add(pStatus, BorderLayout.SOUTH);

            frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
            frame.setVisible(true);
            //dataSource.close();
        }
    });
}

From source file:org.apache.shiro.samples.spring.ui.WebStartView.java

public void afterPropertiesSet() throws Exception {
    ClassPathResource resource = new ClassPathResource("logo.png");
    ImageIcon icon = new ImageIcon(resource.getURL());
    JLabel logo = new JLabel(icon);

    valueField = new JTextField(20);
    updateValueLabel();/*from   w  w  w .  j a v  a  2s  .  co  m*/

    saveButton = new JButton("Save Value");
    saveButton.addActionListener(this);

    refreshButton = new JButton("Refresh Value");
    refreshButton.addActionListener(this);

    JPanel valuePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    valuePanel.add(valueField);
    valuePanel.add(saveButton);
    valuePanel.add(refreshButton);

    secureMethod1Button = new JButton("Method #1");
    secureMethod1Button.addActionListener(this);

    secureMethod2Button = new JButton("Method #2");
    secureMethod2Button.addActionListener(this);

    secureMethod3Button = new JButton("Method #3");
    secureMethod3Button.addActionListener(this);

    JPanel methodPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    methodPanel.add(secureMethod1Button);
    methodPanel.add(secureMethod2Button);
    methodPanel.add(secureMethod3Button);

    frame = new JFrame("Apache Shiro Sample Application");
    frame.setSize(500, 200);

    Container panel = frame.getContentPane();
    panel.setLayout(new BorderLayout());
    panel.add(logo, BorderLayout.NORTH);
    panel.add(valuePanel, BorderLayout.CENTER);
    panel.add(methodPanel, BorderLayout.SOUTH);

    frame.setVisible(true);
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
}