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

/** 
 * Creates a <code>JTextField</code> with the specified text as a label
 * appearing before the text field./*from   ww w .ja  va2 s . co m*/
 * @param label - the text to appear in front of the text field
 * @param length - the length in columns of the text field 
 * @return a <code>JPanel</code> with the labeled text field as the only element
 */
public static JPanel createLabeledTextField(String label, int length) {
    JPanel labeledTextBox = new JPanel();

    JLabel l = new JLabel(label);
    labeledTextBox.add(l);

    JTextField text = new JTextField(length);
    labeledTextBox.add(text);

    return labeledTextBox;
}

From source file:YAxisAlignXButtonMixed.java

private static Container makeIt(String title) {
    JPanel container = new JPanel();
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);//www.  ja  v a  2 s.  co m

    AButton button = new AButton("0.0", 0.0f);
    container.add(button);
    button = new AButton(".25", .25f);
    container.add(button);
    button = new AButton(".50", .50f);
    container.add(button);
    button = new AButton(".75", .75f);
    container.add(button);
    button = new AButton("1.0", 1.0f);
    container.add(button);
    return container;
}

From source file:Main.java

public static JPanel createVerticalPanel(Component topCmp, Component centerCmp) {
    JPanel outPane = new JPanel();
    outPane.setLayout(new BorderLayout());
    outPane.setBorder(new EmptyBorder(5, 5, 5, 5));

    outPane.add(topCmp, BorderLayout.NORTH);
    outPane.add(centerCmp, BorderLayout.CENTER);

    return outPane;
}

From source file:Main.java

/**
 * @return a new panel whose layout forces the original panel to shrink in
 *         size as much as possible./*w  ww  . j a v  a  2s .com*/
 */
public static JPanel wrapInMinimizer(JPanel panel) {
    JPanel result = new JPanel();
    result.setLayout(new BorderLayout());
    result.add(panel, BorderLayout.WEST);

    return result;
}

From source file:Main.java

public static void main_helper(String args[]) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setSize(300, 300);//from w  w w  .  j a v  a 2s .c  o  m

    f.setUndecorated(true);
    f.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);

    JPanel panel = new JPanel();
    panel.setBackground(java.awt.Color.white);
    f.setContentPane(panel);

    MetalLookAndFeel.setCurrentTheme(new MyDefaultMetalTheme());

    try {
        UIManager.setLookAndFeel(new MetalLookAndFeel());
    } catch (Exception e) {
        e.printStackTrace();
    }

    SwingUtilities.updateComponentTreeUI(f);

    f.setVisible(true);

}

From source file:EdgeLayoutExample.java

public static JPanel createPanel() {
    JPanel outerPanel = new JPanel();
    outerPanel.setLayout(new EdgeLayout());
    outerPanel.add(new JButton("West1"), EdgeLayout.WEST);
    outerPanel.add(new JButton("North1"), EdgeLayout.NORTH);
    outerPanel.add(new JButton("West2"), EdgeLayout.WEST);
    outerPanel.add(new JButton("North2"), EdgeLayout.NORTH);
    outerPanel.add(new JButton("East1"), EdgeLayout.EAST);
    outerPanel.add(new JButton("South1"), EdgeLayout.SOUTH);
    outerPanel.add(new JButton("West3"), EdgeLayout.WEST);
    outerPanel.add(new JButton("West4"), EdgeLayout.WEST);
    outerPanel.add(new JButton("South2"), EdgeLayout.SOUTH);
    outerPanel.add(new JButton("South3"), EdgeLayout.SOUTH);
    outerPanel.add(new JButton("Center1"), EdgeLayout.CENTER);
    return outerPanel;
}

From source file:Main.java

/**
 * @param title/*from   w  ww  . ja v  a2  s.com*/
 * @param comp 
 * @return jpanel
 */
public static JPanel createTitledScrollComponent(String title, Component comp) {
    JScrollPane scroll = new JScrollPane(comp);
    scroll.setWheelScrollingEnabled(true);
    scroll.setPreferredSize(new Dimension(1, 1));
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createTitledBorder(title));
    panel.setLayout(new BorderLayout());
    panel.add(scroll, BorderLayout.CENTER);
    return panel;
}

From source file:Main.java

/**
 * @return A new JPanel
 * @since 2.5.0
 */
public static JPanel newPanel() {
    return new JPanel();
}

From source file:Main.java

public static JPanel createTextComponentPane(String labelText, JTextComponent textComp, Font font,
        Color bgColor, boolean isVertical) {
    JPanel outPane = new JPanel();
    outPane.setLayout(new BorderLayout());
    outPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    JLabel labelOut = new JLabel(labelText, SwingConstants.LEFT);
    if (isVertical) {
        outPane.add(labelOut, BorderLayout.NORTH);
    } else {/*from   w w w.ja  v  a  2s . c om*/
        outPane.add(labelOut, BorderLayout.WEST);
    }
    if (textComp instanceof JTextArea) {
        outPane.add(createScrollPane((JTextArea) textComp, font, bgColor), BorderLayout.CENTER);
    } else {
        textComp.setBackground(bgColor);
        textComp.setFont(font);
        outPane.add(textComp, BorderLayout.CENTER);
    }
    return outPane;
}

From source file:Main.java

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