List of usage examples for javax.swing JPanel add
public Component add(Component comp)
From source file:com.sshtools.common.ui.OptionsPanel.java
/** * * * @param parent/*ww w . j av a 2 s . c om*/ * @param tabs tabs * * @return */ public static boolean showOptionsDialog(Component parent, OptionsTab[] tabs) { final OptionsPanel opts = new OptionsPanel(tabs); opts.reset(); JDialog d = null; Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class, parent); if (w instanceof JDialog) { d = new JDialog((JDialog) w, "Options", true); } else if (w instanceof JFrame) { d = new JDialog((JFrame) w, "Options", true); } else { d = new JDialog((JFrame) null, "Options", true); } final JDialog dialog = d; // Create the bottom button panel final JButton cancel = new JButton("Cancel"); cancel.setMnemonic('c'); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { opts.cancelled = true; dialog.setVisible(false); } }); final JButton ok = new JButton("Ok"); ok.setMnemonic('o'); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (opts.validateTabs()) { dialog.setVisible(false); } } }); dialog.getRootPane().setDefaultButton(ok); JPanel buttonPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(6, 6, 0, 0); gbc.weighty = 1.0; UIUtil.jGridBagAdd(buttonPanel, ok, gbc, GridBagConstraints.RELATIVE); UIUtil.jGridBagAdd(buttonPanel, cancel, gbc, GridBagConstraints.REMAINDER); JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0)); southPanel.add(buttonPanel); // JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); mainPanel.add(opts, BorderLayout.CENTER); mainPanel.add(southPanel, BorderLayout.SOUTH); // Show the dialog dialog.getContentPane().setLayout(new GridLayout(1, 1)); dialog.getContentPane().add(mainPanel); dialog.pack(); dialog.setResizable(true); UIUtil.positionComponent(SwingConstants.CENTER, dialog); dialog.setVisible(true); if (!opts.cancelled) { opts.applyTabs(); } return !opts.cancelled; }
From source file:AlignX.java
private static Container makeIt(String labelChar, float alignment) { JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); container.setLayout(layout);/*from ww w . jav a 2 s .com*/ for (int i = 1; i < 6; i++) { String label = makeLabel(labelChar, i * 2); JButton button = new JButton(label); button.setAlignmentX(alignment); container.add(button); } return container; }
From source file:Main.java
public static JPanel createFlow(final int align, final int gap, final Object... components) { final JPanel jp = new JPanel(new FlowLayout(align, gap, gap)); jp.setBorder(BorderFactory.createEmptyBorder()); for (final Object component : components) { if (component instanceof Component) { initComponentHeight((Component) component); jp.add((Component) component); } else if (component instanceof Number) { jp.add(Box.createHorizontalStrut(((Number) component).intValue())); }//from w ww.ja va2 s . c o m } return jp; }
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);//w w w.j a 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: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);/* ww w . jav a2s .co 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:layout.SpringGrid.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread.// w w w .j ava 2s. co m */ private static void createAndShowGUI() { //Create the panel and populate it. JPanel panel = new JPanel(new SpringLayout()); for (int i = 0; i < 9; i++) { JTextField textField = new JTextField(Integer.toString(i)); //Make the 4th field extra big. if (i == 4) { textField.setText("This one is extra long."); } panel.add(textField); } //Lay out the panel. SpringUtilities.makeGrid(panel, 3, 3, //rows, cols 5, 5, //initialX, initialY 5, 5);//xPad, yPad //Create and set up the window. JFrame frame = new JFrame("SpringGrid"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. panel.setOpaque(true); //content panes must be opaque frame.setContentPane(panel); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static JComponent scrollV(String title, JComponent content) { JPanel p = new JPanel(new BorderLayout()); p.setBorder(BorderFactory.createTitledBorder(title)); JScrollPane scroll = new JScrollPane(content); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); p.add(scroll); return p;/*from ww w . j a v a 2 s . c om*/ }
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);/*ww w .ja v a2 s . com*/ 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: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);//from ww w . j a va 2 s . com 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:SpringForm.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread.//w ww. j ava 2 s . c o m */ private static void createAndShowGUI() { String[] labels = { "Name: ", "Fax: ", "Email: ", "Address: " }; int numPairs = labels.length; //Create and populate the panel. JPanel p = new JPanel(new SpringLayout()); for (int i = 0; i < numPairs; i++) { JLabel l = new JLabel(labels[i], JLabel.TRAILING); p.add(l); JTextField textField = new JTextField(10); l.setLabelFor(textField); p.add(textField); } //Lay out the panel. SpringUtilities.makeCompactGrid(p, numPairs, 2, //rows, cols 6, 6, //initX, initY 6, 6); //xPad, yPad //Create and set up the window. JFrame frame = new JFrame("SpringForm"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. p.setOpaque(true); //content panes must be opaque frame.setContentPane(p); //Display the window. frame.pack(); frame.setVisible(true); }