Example usage for javax.swing JPanel add

List of usage examples for javax.swing JPanel add

Introduction

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

Prototype

public Component add(String name, Component comp) 

Source Link

Document

Adds the specified component to this container.

Usage

From source file:Main.java

public static void showFrameWithToolBar(String toolBarPosition) {

    JPanel gui = new JPanel(new BorderLayout());

    JToolBar tb = new JToolBar();

    gui.add(tb, toolBarPosition);
    tb.add(new JButton("Button 1"));
    tb.add(new JButton("Button 2"));
    tb.addSeparator();/*from  w  w w.  ja v  a2 s.c  o  m*/
    tb.add(new JButton("Button 3"));
    tb.add(new JCheckBox("Check 1", true));

    JFrame f = new JFrame(toolBarPosition);
    f.setContentPane(gui);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLocationByPlatform(true);
    f.pack();

    f.setSize(400, 120);
    f.setVisible(true);
}

From source file:Main.java

public static JComponent wrapBorder(Component content, Border border) {
    JPanel wrapper = new JPanel(new BorderLayout());
    wrapper.add(content, BorderLayout.CENTER);
    wrapper.setBorder(border);/* ww  w  .ja  v a  2s  . c o  m*/
    return wrapper;
}

From source file:Main.java

/**
 * @return a new panel whose layout forces the original panel to shrink in
 *         size as much as possible./*from   w  ww.  j a  v a2 s  .  c om*/
 */
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 addSeparator(JPanel panel, String text) {
    JLabel l = createLabel(text);
    l.setForeground(LABEL_COLOR);/*www . j  av a  2s . c  o m*/

    panel.add(l, "gapbottom 1, span, split 2, aligny center");
    panel.add(configureActiveComponent(new JSeparator()), "gapleft rel, growx");
}

From source file:Main.java

public static void setupNowLoadingPanel(JPanel panel) {
    JLabel loading = new JLabel("Loading...", SwingConstants.CENTER);
    panel.setLayout(new BorderLayout());
    panel.add(loading, BorderLayout.CENTER);
    panel.revalidate();//from   w ww  .  j a  v a2  s.  c om
    panel.repaint();
}

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

static void createFrameAtLocation(Point p) {
    JFrame frame = new JFrame();
    frame.setTitle("Test frame on two screens");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new BorderLayout());
    JTextArea textareaA = new JTextArea(24, 80);
    textareaA.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 1));
    panel.add(textareaA, BorderLayout.CENTER);
    frame.setLocation(p);/*  w  w  w  . j  a  v a 2  s.  c o  m*/
    frame.add(panel);
    frame.pack();
    frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    frame.setVisible(true);
}

From source file:Main.java

/**
 * @param title/*w  ww  . j av a  2s . c om*/
 * @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:ec.nbdemetra.ui.demo.ComponentsDemo.java

private static Component configure(Component c) {
    if (c instanceof ExceptionPanel || c instanceof ReflectComponent) {
        return c;
    }//from ww w.jav  a 2s.com
    JToolBar toolBar = NbComponents.newInnerToolbar();
    for (DemoComponentHandler o : Lookup.getDefault().lookupAll(DemoComponentHandler.class)) {
        if (o.canHandle(c)) {
            o.configure(c);
            o.fillToolBar(toolBar, c);
        }
    }
    if (toolBar.getComponentCount() > 0) {
        JPanel result = new JPanel(new BorderLayout());
        result.add(c, BorderLayout.CENTER);
        result.add(toolBar, BorderLayout.NORTH);
        return result;
    }
    return c;
}

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 ww  .  ja  va2s  .  co 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;
}