Example usage for javax.swing JPanel setLayout

List of usage examples for javax.swing JPanel setLayout

Introduction

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

Prototype

public void setLayout(LayoutManager mgr) 

Source Link

Document

Sets the layout manager for this container.

Usage

From source file:SystemFontDisplayer.java

public SystemFontDisplayer() {
    Container container = getContentPane();
    displayPanel = new DisplayPanel();
    container.add(displayPanel);//from ww w.jav a2s.  com
    JPanel controlPanel = new JPanel();
    controlPanel.setLayout(new GridLayout(1, 3));

    fontsBox = new JComboBox(displayPanel.fontFamilyNames);
    fontsBox.setSelectedItem("Arial");
    fontsBox.addActionListener(new ComboBoxListener());

    fontStylesBox.addActionListener(new ComboBoxListener());

    fontSizesBox.setSelectedItem("36");
    fontSizesBox.addActionListener(new ComboBoxListener());
    controlPanel.add(fontsBox);
    controlPanel.add(fontStylesBox);
    controlPanel.add(fontSizesBox);
    container.add(BorderLayout.SOUTH, controlPanel);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setSize(400, 250);
    setVisible(true);
}

From source file:SwingSuspendResume.java

public SwingSuspendResume() {
    symbolTF = new JTextField();
    symbolTF.setEditable(false);//w  w  w .  j  av  a2  s.c  om
    symbolTF.setFont(new Font("Monospaced", Font.BOLD, 26));
    symbolTF.setHorizontalAlignment(JTextField.CENTER);

    final JButton suspendB = new JButton("Suspend");
    final JButton resumeB = new JButton("Resume");

    suspendB.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            suspendNow();
        }
    });

    resumeB.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            resumeNow();
        }
    });

    JPanel innerStackP = new JPanel();
    innerStackP.setLayout(new GridLayout(0, 1, 3, 3));
    innerStackP.add(symbolTF);
    innerStackP.add(suspendB);
    innerStackP.add(resumeB);

    this.setLayout(new FlowLayout(FlowLayout.CENTER));
    this.add(innerStackP);
}

From source file:org.spantus.exp.segment.exec.DrawSegmentAnalysis.java

protected JFrame getFrame() {
    if (frame == null) {
        frame = new JFrame("Analysis result");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0, 2));
        frame.setContentPane(panel);/*w w w . j av a 2  s .c o m*/
    }
    return frame;
}

From source file:TextComponentTest.java

public TextComponentFrame() {
    setTitle("TextComponentTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    final JTextField textField = new JTextField();
    final JPasswordField passwordField = new JPasswordField();

    JPanel northPanel = new JPanel();
    northPanel.setLayout(new GridLayout(2, 2));
    northPanel.add(new JLabel("User name: ", SwingConstants.RIGHT));
    northPanel.add(textField);//from  w w w  . j ava  2s  . c o  m
    northPanel.add(new JLabel("Password: ", SwingConstants.RIGHT));
    northPanel.add(passwordField);

    add(northPanel, BorderLayout.NORTH);

    final JTextArea textArea = new JTextArea(8, 40);
    JScrollPane scrollPane = new JScrollPane(textArea);

    add(scrollPane, BorderLayout.CENTER);

    // add button to append text into the text area

    JPanel southPanel = new JPanel();

    JButton insertButton = new JButton("Insert");
    southPanel.add(insertButton);
    insertButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            textArea.append("User name: " + textField.getText() + " Password: "
                    + new String(passwordField.getPassword()) + "\n");
        }
    });

    add(southPanel, BorderLayout.SOUTH);

    // add a text area with scroll bars

}

From source file:SysConfig.java

public SysConfig() {
    super("JTabbedPane & BoxLayout Demonstration");
    setSize(500, 300);//w ww.j  a v  a2  s  .  c  o m
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JPanel configPane = new JPanel();
    configPane.setLayout(new BoxLayout(configPane, BoxLayout.Y_AXIS));
    JTextArea question = new JTextArea("Which of the following options\n" + "do you have installed?");
    // Ok, now configure the textarea to show up properly inside the box.
    // This is part of the "high art" of Swing...
    question.setEditable(false);
    question.setMaximumSize(new Dimension(300, 50));
    question.setAlignmentX(0.0f);
    question.setBackground(configPane.getBackground());

    JCheckBox audioCB = new JCheckBox("Sound Card", true);
    JCheckBox nicCB = new JCheckBox("Ethernet Card", true);
    JCheckBox tvCB = new JCheckBox("Video Out", false);

    configPane.add(Box.createVerticalGlue());
    configPane.add(question);
    configPane.add(audioCB);
    configPane.add(nicCB);
    configPane.add(tvCB);
    configPane.add(Box.createVerticalGlue());

    JLabel audioPane = new JLabel("Audio stuff");
    JLabel nicPane = new JLabel("Networking stuff");
    JLabel tvPane = new JLabel("Video stuff");
    JLabel helpPane = new JLabel("Help information");

    audioCB.addItemListener(new TabManager(audioPane));
    nicCB.addItemListener(new TabManager(nicPane));
    tvCB.addItemListener(new TabManager(tvPane));

    config.addTab("System", null, configPane, "Choose Installed Options");
    config.addTab("Audio", null, audioPane, "Audio system configuration");
    config.addTab("Networking", null, nicPane, "Networking configuration");
    config.addTab("Video", null, tvPane, "Video system configuration");
    config.addTab("Help", null, helpPane, "How Do I...");

    getContentPane().add(config, BorderLayout.CENTER);
}

From source file:ClipArea.java

public ClipArea() {
    super();//from  www.ja va  2s . co m
    Container contentPane = getContentPane();

    canvas = new MyCanvas();
    contentPane.add(canvas);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(1, 2));
    clipButton = new JRadioButton("Clip", true);
    clipButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            canvas.clip = true;
            canvas.clipFurther = false;
            canvas.repaint();
        }
    });
    clipFurButton = new JRadioButton("Clip Further");
    clipFurButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            canvas.clipFurther = true;
            canvas.repaint();
        }
    });
    ButtonGroup group = new ButtonGroup();
    group.add(clipButton);
    group.add(clipFurButton);

    panel.add(clipButton);
    panel.add(clipFurButton);
    contentPane.add(BorderLayout.SOUTH, panel);

    // 4. Add a window listener to close the frame properly.
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    pack();
    setVisible(true);
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());

    JPanel upper = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    upper.setLayout(gridbag);
    GridBagConstraints gbc = new GridBagConstraints();

    JButton toolbar1 = new JButton("toolbar1");
    JButton toolbar2 = new JButton("toolbar2");
    JButton toolbar3 = new JButton("toolbar3");

    gbc.gridx = 0;/*  w w w  .ja v  a  2  s  . c om*/
    gbc.gridy = 0;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.WEST;
    upper.add(toolbar1, gbc);

    gbc.gridx = 1;
    gbc.anchor = GridBagConstraints.CENTER;
    upper.add(toolbar2, gbc);

    gbc.gridx = 2;
    gbc.anchor = GridBagConstraints.EAST;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    upper.add(toolbar3, gbc);

    add(upper, BorderLayout.NORTH);

    JPanel something = new JPanel();
    something.setBackground(Color.WHITE);
    something.setPreferredSize(new Dimension(600, 600));
    something.repaint();
    add(something, BorderLayout.CENTER);

    pack();
    setVisible(true);
}

From source file:layout.BoxLayoutDemo2.java

public void populateContentPane(Container contentPane) {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));

    //Create the rectangles.
    int shortSideSize = 15;
    for (int i = 0; i < NUM_COMPONENTS; i++) {
        if (sizeIsRandom) {
            shortSideSize = (int) (30.0 * Math.random()) + 30;
        } else {//from www  . j a va 2  s  .c  o m
            shortSideSize += 10;
        }
        bldComponent[i] = new BLDComponent(xAlignment[i], hue[i], shortSideSize, restrictSize, sizeIsRandom,
                String.valueOf(i));
        panel.add(bldComponent[i]);
    }

    //Create the instructions.
    JLabel label = new JLabel("Click a rectangle to " + "change its X alignment.");
    JCheckBox cb = new JCheckBox("Restrict maximum rectangle size.");
    cb.setSelected(restrictSize);
    cb.addItemListener(this);

    panel.setBorder(BorderFactory.createLineBorder(Color.red));

    Box box = Box.createVerticalBox();
    box.add(label);
    box.add(cb);

    contentPane.add(panel, BorderLayout.CENTER);
    contentPane.add(box, BorderLayout.PAGE_END);
}

From source file:ScrollDemo2.java

public void init() {
    JRadioButton form[][] = new JRadioButton[12][5];
    String counts[] = { "", "0-1", "2-5", "6-10", "11-100", "101+" };
    String categories[] = { "Household", "Office", "Extended Family", "Company (US)", "Company (World)", "Team",
            "Will", "Birthday Card List", "High School", "Country", "Continent", "Planet" };
    JPanel p = new JPanel();
    p.setSize(600, 400);/*from  w w w.j a va2s.  com*/
    p.setLayout(new GridLayout(13, 6, 10, 0));
    for (int row = 0; row < 13; row++) {
        ButtonGroup bg = new ButtonGroup();
        for (int col = 0; col < 6; col++) {
            if (row == 0) {
                p.add(new JLabel(counts[col]));
            } else {
                if (col == 0) {
                    p.add(new JLabel(categories[row - 1]));
                } else {
                    form[row - 1][col - 1] = new JRadioButton();
                    bg.add(form[row - 1][col - 1]);
                    p.add(form[row - 1][col - 1]);
                }
            }
        }
    }
    scrollpane = new JScrollPane(p);

    // Add in some JViewports for the column and row headers
    JViewport jv1 = new JViewport();
    jv1.setView(new JLabel(new ImageIcon("columnlabel.gif")));
    scrollpane.setColumnHeader(jv1);
    JViewport jv2 = new JViewport();
    jv2.setView(new JLabel(new ImageIcon("rowlabel.gif")));
    scrollpane.setRowHeader(jv2);

    // And throw in an information button
    JButton jb1 = new JButton(new ImageIcon("question.gif"));
    jb1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            JOptionPane.showMessageDialog(null, "This is an Active Corner!", "Information",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    });
    scrollpane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, jb1);
    getContentPane().add(scrollpane, BorderLayout.CENTER);
}

From source file:com.floreantpos.config.ui.OtherConfigurationView.java

public OtherConfigurationView() {
    setLayout(new BorderLayout());

    JPanel contentPanel = new JPanel();
    contentPanel.setLayout(new MigLayout("", "[][]", "[]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    tfMapApiKey = new FixedLengthTextField(); //$NON-NLS-1$
    tfMapApiKey.setLength(220);// w w  w .j  a v  a 2 s  .  c o  m
    contentPanel.add(new JLabel(Messages.getString("OtherConfigurationView.0"))); //$NON-NLS-1$
    contentPanel.add(tfMapApiKey); //$NON-NLS-1$

    JScrollPane scrollPane = new JScrollPane(contentPanel);
    scrollPane.setBorder(null);
    add(scrollPane);
}