Example usage for javax.swing JPanel JPanel

List of usage examples for javax.swing JPanel JPanel

Introduction

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

Prototype

public JPanel() 

Source Link

Document

Creates a new JPanel with a double buffer and a flow layout.

Usage

From source file:JListBackground.java

public static void addComponentsToPane(Container pane) {
    String[] bruteForceCode = { "int count = 0", "int m = mPattern.length();", "int n = mSource .length();",
            "outer:", " ++count;", " }", " return count;", "}" };
    JList list = new JList(bruteForceCode);
    Border etch = BorderFactory.createEtchedBorder();
    list.setBorder(BorderFactory.createTitledBorder(etch, "Brute Force Code"));
    JPanel listPanel = new JPanel();
    listPanel.add(list);/*from  w ww . ja va  2  s. c  o m*/
    listPanel.setBackground(lightBlue);
    list.setBackground(lightBlue);

    pane.add(listPanel, BorderLayout.CENTER);
    pane.setBackground(lightBlue);
}

From source file:Main.java

/**
 * Creates a panel that contains all of the components on top of each other in north,
 * and tries to make them as small as possible (probably by using getPreferredSize()).
 *
 * @deprecated use proper layout, usually no need to use such complex/ugly layouting
 *///from   w  w  w  .  j  av a2  s. c o m
public static JPanel combineInNorth(JComponent[] components) {
    JPanel result = new JPanel();
    if (components.length == 0) {
        return result;
    }
    result.setLayout(new BorderLayout());
    JPanel contentPanel = new JPanel();
    result.add(contentPanel, BorderLayout.NORTH);
    contentPanel.setLayout(new GridBagLayout());

    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.weightx = 1.0;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    for (int i = 0; i < components.length; i++) {
        contentPanel.add(components[i], constraints);
    }
    if (result.isVisible())
        result.doLayout();
    return result;
}

From source file:Main.java

/**
 * @param okText/*from ww w.  ja va  2  s.co  m*/
 * @param cancelText
 * @param listener
 * @param root 
 * @return newly created JPanel with ok and cancel buttons
 */
public static JPanel createOkCancelPanel(String okText, String cancelText, ActionListener listener,
        JRootPane root) {
    JPanel panel = new JPanel();
    JButton ok = new JButton(okText);
    JButton cancel = new JButton(cancelText);
    panel.add(ok);
    panel.add(cancel);
    ok.addActionListener(listener);
    ok.setActionCommand(okText);
    if (root != null)
        root.setDefaultButton(ok);
    cancel.addActionListener(listener);
    cancel.setActionCommand(cancelText);
    return panel;
}

From source file:Main.java

public Main() {
    super("Test");
    setSize(200, 200);/*from  ww w  .  j  a va2s  .  com*/

    JPanel panel = new JPanel();
    setContentPane(panel);

    JButton button1 = new JButton("Button 1");
    JButton button2 = new JButton("Button 2");
    JButton button3 = new JButton("Button 3");

    button1.setBounds(10, 10, 100, 40);
    button2.setBounds(5, 5, 100, 30);
    button3.setBounds(15, 15, 150, 40);

    panel.setLayout(null);

    panel.add(button1);
    panel.add(button2);
    panel.add(button3);

    panel.setComponentZOrder(button1, 1);
    panel.setComponentZOrder(button2, 0);
    panel.setComponentZOrder(button3, 2);

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    panel.setPreferredSize(new Dimension(333, 666));
    add(panel);//  ww  w.  j  a v  a  2s  .  c  o  m
    pack();
    if (Toolkit.getDefaultToolkit().isFrameStateSupported(MAXIMIZED_BOTH)) {
        setExtendedState(MAXIMIZED_BOTH);
    } else {
        Dimension max = Toolkit.getDefaultToolkit().getScreenSize();
        max.height -= 20;
        setSize(max);
        setLocation(0, 20);
    }
    setVisible(true);
}

From source file:Main.java

public Main() {
    JPanel panel = new JPanel();
    getContentPane().add(panel);/* ww w  .j ava 2 s  .c  o  m*/
    setSize(450, 450);

    JButton button = new JButton("press");
    panel.add(button);
}