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

private static Container makeIt(String title, float alignment) {
    String labels[] = { "--", "--", "--" };

    JPanel container = new JPanel();
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS);
    container.setLayout(layout);/*ww w .  j av a 2s.  co  m*/

    for (int i = 0, n = labels.length; i < n; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentY(alignment);
        container.add(button);
    }
    return container;
}

From source file:XAxisAlignY.java

private static Container layoutComponents(String title, float alignment) {
    String labels[] = { "-", "-", "-" };

    JPanel container = new JPanel();
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS);
    container.setLayout(layout);/*from   w  w w. ja  va  2  s  . co  m*/
    for (int i = 0, n = labels.length; i < n; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentY(alignment);
        container.add(button);
    }
    return container;
}

From source file:Main.java

private static final Component group(final Component[] components, final int axis) {
    final JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, axis));

    for (final Component component : components) {
        panel.add(component);//w w w .  j a va2s  .  c om
    }

    return panel;
}

From source file:YAxisAlignX.java

private static Container makeIt(String title, float alignment) {
    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);/*from  w  ww  .  ja  v a  2s .  c o  m*/

    for (int i = 0, n = labels.length; i < n; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentX(alignment);
        container.add(button);
    }
    return container;
}

From source file:Main.java

/**
 * Places the given components in a JPanel with a FlowLayout.
 * @param components the components to add
 * @return a JPanel with a FlowLayout with the given components
 *//*  www.j  av  a 2  s  .  c o m*/
public static JPanel flowLayout(Component... components) {
    final JPanel result = new JPanel(); // FlowLayout is default
    Arrays.stream(components).forEach(result::add);
    return result;
}

From source file:YAxisAlignX.java

private static Container layoutComponents(String title, float alignment) {
    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);/*from   w  w w. jav a  2s  .  c o  m*/

    for (int i = 0, n = labels.length; i < n; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentX(alignment);
        container.add(button);
    }
    return container;
}

From source file:Main.java

/**
 * "Wraps" a component in a JPanel. In layouts where components tend to stretch, this is
 * useful because the JPanel will stretch but the actual component will not.
 * @return A JPanel containing the specified component.
 *///from  w  w  w.  j  a  va  2 s  . c o m
public static JPanel box(Component component) {
    JPanel panel = new JPanel();
    panel.add(component);
    return panel;
}

From source file:XAxisDiffAlign.java

private static Container makeIt(String title, boolean more) {
    JPanel container = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets();
            int width = getWidth();
            int height = getHeight() - insets.top - insets.bottom;
            int halfHeight = height / 2 + insets.top;
            g.drawLine(0, halfHeight, width, halfHeight);
        }/*  w ww  .j a v  a 2  s.c o  m*/
    };
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS);
    container.setLayout(layout);

    JButton button;
    button = new JButton("0.0");
    button.setOpaque(false);
    button.setAlignmentY(Component.TOP_ALIGNMENT);
    container.add(button);
    if (more) {
        button = new JButton(".25");
        button.setOpaque(false);
        button.setAlignmentY(0.25f);
        container.add(button);
        button = new JButton(".5");
        button.setOpaque(false);
        button.setAlignmentY(Component.CENTER_ALIGNMENT);
        container.add(button);
        button = new JButton(".75");
        button.setOpaque(false);
        button.setAlignmentY(0.75f);
        container.add(button);
    }
    button = new JButton("1.0");
    button.setOpaque(false);
    button.setAlignmentY(Component.BOTTOM_ALIGNMENT);
    container.add(button);

    return container;
}

From source file:Main.java

private static JPanel createPanel() {
    JPanel panel = new JPanel();
    DefaultTableModel model = new DefaultTableModel() {
        @Override/* ww w . j  a  v a2s. c  o  m*/
        public Class<?> getColumnClass(int col) {
            if (col == 0) {
                return Icon.class;
            } else {
                return Double.class;
            }
        }
    };
    model.setColumnIdentifiers(new Object[] { "Book", "Cost" });
    for (int i = 0; i < 42; i++) {
        model.addRow(new Object[] { ICON, Double.valueOf(i) });
    }
    JTable table = new JTable(model);
    table.setDefaultRenderer(Double.class, new DefaultTableCellRenderer() {
        @Override
        protected void setValue(Object value) {
            NumberFormat format = NumberFormat.getCurrencyInstance();
            setText((value == null) ? "" : format.format(value));
        }
    });
    table.setRowHeight(ICON.getIconHeight());
    panel.add(new JScrollPane(table) {
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(320, 240);
        }
    });
    return panel;
}

From source file:YAxisDiffAlign.java

private static Container makeIt(String title, boolean more) {
    JPanel container = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets();
            int width = getWidth() - insets.left - insets.right;
            int halfWidth = width / 2 + insets.left;
            int height = getHeight();
            int halfHeight = height / 2 + insets.top;
            g.drawLine(halfWidth, 0, halfWidth, height);
        }//from w  w  w.java  2s . c  o m
    };
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);

    JButton button;
    button = new JButton("0.0");
    button.setOpaque(false);
    button.setAlignmentX(Component.LEFT_ALIGNMENT);
    container.add(button);
    if (more) {
        button = new JButton(".25");
        button.setOpaque(false);
        button.setAlignmentX(0.25f);
        container.add(button);
        button = new JButton(".5");
        button.setOpaque(false);
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        container.add(button);
        button = new JButton(".75");
        button.setOpaque(false);
        button.setAlignmentX(0.75f);
        container.add(button);
    }
    button = new JButton("1.0");
    button.setOpaque(false);
    button.setAlignmentX(Component.RIGHT_ALIGNMENT);
    container.add(button);

    return container;
}