List of usage examples for javax.swing JPanel add
public Component add(Component comp)
From source file:Main.java
/** * Put a series of {@link JComponent}s in a {@link JPanel} which has a {@link FlowLayout}. * * @param position//from w ww.j a va 2 s . c o m * Position of components, left, right, or center justified (for example, {@link * java.awt.FlowLayout#CENTER)} * @param opaque * True if the returned JPanel should be opaque * @param firstComponent * The first {@link JComponent} to add * @param remainingComponents * The rest of the {@link JComponent}s to add * @return A {@link JPanel} with a {@link FlowLayout} which contains all the passed {@link JComponent}s. */ public static JPanel putComponentsInFlowLayoutPanel(int position, boolean opaque, JComponent firstComponent, JComponent... remainingComponents) { JPanel flowLayoutPanel = new JPanel(new FlowLayout(position)); flowLayoutPanel.setOpaque(opaque); flowLayoutPanel.add(firstComponent); for (JComponent component : remainingComponents) { flowLayoutPanel.add(component); } return flowLayoutPanel; }
From source file:Main.java
/** * @param okText/* ww w. jav a 2s.c o 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; }
From source file:Main.java
public static void showDialogWhitImage(URL pathuRL) { JPanel panel = new JPanel(); JLabel jLabel = new JLabel(); jLabel.setIcon(new javax.swing.ImageIcon(pathuRL)); // NOI18N panel.add(jLabel); JOptionPane.showMessageDialog(null, panel); jLabel = null;/*from w ww . j a va 2 s . c o m*/ panel = null; }
From source file:Main.java
/** * Returns a "warning"-colored panel with given message. * //w w w .j av a 2s . co m * @param context * @param message * @return */ public static JPanel constructWarningPanel(String message) { JPanel p = new JPanel(); JLabel l = new JLabel(message); // "magical" color p.setBackground(new Color(240, 40, 70)); p.add(l); return p; }
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); }/*from www. j a v a 2 s . c o m*/ return panel; }
From source file:Wallpaper.java
private static JPanel createPanel() { JPanel p = new JPanel(); ButtonGroup entreeGroup = new ButtonGroup(); JRadioButton radioButton;/* w ww.j a v a 2s .com*/ p.add(radioButton = new JRadioButton("Beef", true)); entreeGroup.add(radioButton); p.add(radioButton = new JRadioButton("Chicken")); entreeGroup.add(radioButton); p.add(radioButton = new JRadioButton("Vegetable")); entreeGroup.add(radioButton); p.add(new JCheckBox("Ketchup")); p.add(new JCheckBox("Mustard")); p.add(new JCheckBox("Pickles")); p.add(new JLabel("Special requests:")); p.add(new JTextField(20)); JButton orderButton = new JButton("Place Order"); p.add(orderButton); return p; }
From source file:FieldValidator.java
private static JComponent createContent() { Dimension labelSize = new Dimension(80, 20); Box box = Box.createVerticalBox(); // A single LayerUI for all the fields. LayerUI<JFormattedTextField> layerUI = new ValidationLayerUI(); // Number field. JLabel numberLabel = new JLabel("Number:"); numberLabel.setHorizontalAlignment(SwingConstants.RIGHT); numberLabel.setPreferredSize(labelSize); NumberFormat numberFormat = NumberFormat.getInstance(); JFormattedTextField numberField = new JFormattedTextField(numberFormat); numberField.setColumns(16);/*w w w. ja va2s.co m*/ numberField.setFocusLostBehavior(JFormattedTextField.PERSIST); numberField.setValue(42); JPanel numberPanel = new JPanel(); numberPanel.add(numberLabel); numberPanel.add(new JLayer<JFormattedTextField>(numberField, layerUI)); // Date field. JLabel dateLabel = new JLabel("Date:"); dateLabel.setHorizontalAlignment(SwingConstants.RIGHT); dateLabel.setPreferredSize(labelSize); DateFormat dateFormat = DateFormat.getDateInstance(); JFormattedTextField dateField = new JFormattedTextField(dateFormat); dateField.setColumns(16); dateField.setFocusLostBehavior(JFormattedTextField.PERSIST); dateField.setValue(new java.util.Date()); JPanel datePanel = new JPanel(); datePanel.add(dateLabel); datePanel.add(new JLayer<JFormattedTextField>(dateField, layerUI)); // Time field. JLabel timeLabel = new JLabel("Time:"); timeLabel.setHorizontalAlignment(SwingConstants.RIGHT); timeLabel.setPreferredSize(labelSize); DateFormat timeFormat = DateFormat.getTimeInstance(); JFormattedTextField timeField = new JFormattedTextField(timeFormat); timeField.setColumns(16); timeField.setFocusLostBehavior(JFormattedTextField.PERSIST); timeField.setValue(new java.util.Date()); JPanel timePanel = new JPanel(); timePanel.add(timeLabel); timePanel.add(new JLayer<JFormattedTextField>(timeField, layerUI)); // Put them all in the box. box.add(Box.createGlue()); box.add(numberPanel); box.add(Box.createGlue()); box.add(datePanel); box.add(Box.createGlue()); box.add(timePanel); return box; }
From source file:de.dakror.virtualhub.server.dialog.BackupEditDialog.java
public static void show() throws JSONException { final JDialog dialog = new JDialog(Server.currentServer.frame, "Backup-Einstellungen", true); dialog.setSize(400, 250);// w w w . j a va 2 s . c om dialog.setLocationRelativeTo(Server.currentServer.frame); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); JPanel cp = new JPanel(new SpringLayout()); cp.add(new JLabel("Zielverzeichnis:")); JPanel panel = new JPanel(); final JTextField path = new JTextField((Server.currentServer.settings.has("backup.path") ? Server.currentServer.settings.getString("backup.path") : ""), 10); panel.add(path); panel.add(new JButton(new AbstractAction("Whlen...") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { JFileChooser jfc = new JFileChooser((path.getText().length() > 0 ? new File(path.getText()) : new File(System.getProperty("user.home")))); jfc.setFileHidingEnabled(false); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setDialogTitle("Backup-Zielverzeichnis whlen"); if (jfc.showOpenDialog(dialog) == JFileChooser.APPROVE_OPTION) path.setText(jfc.getSelectedFile().getPath().replace("\\", "/")); } })); cp.add(panel); cp.add(new JLabel("")); cp.add(new JLabel("")); cp.add(new JButton(new AbstractAction("Abbrechen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } })); cp.add(new JButton(new AbstractAction("Speichern") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { try { if (path.getText().length() > 0) Server.currentServer.settings.put("backup.path", path.getText()); dialog.dispose(); } catch (JSONException e1) { e1.printStackTrace(); } } })); SpringUtilities.makeCompactGrid(cp, 3, 2, 6, 6, 6, 6); dialog.setContentPane(cp); dialog.pack(); dialog.setVisible(true); }
From source file:Main.java
/** * @param okText//from w ww .j av a2s.c om * @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
/** * Creates a <code>JPanel</code> containing the given text placed in the * center as the only component./* w w w.j ava2 s . c o m*/ * @param text - the text to put on the panel * @return a JPanel containing only the given text */ public static JPanel makeTextPanel(String text) { JPanel panel = new JPanel(false); JLabel filler = new JLabel(text); filler.setHorizontalAlignment(SwingConstants.CENTER); panel.setLayout(new GridLayout(1, 1)); panel.add(filler); return panel; }