List of usage examples for javax.swing JPanel add
public Component add(String name, Component comp)
From source file:FormattedSample.java
public static void main(final String args[]) { JFrame frame = new JFrame("Formatted Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel datePanel = new JPanel(new BorderLayout()); DateFormat format = new SimpleDateFormat("yyyy--MMMM--dd"); JFormattedTextField dateTextField = new JFormattedTextField(format); datePanel.add(dateTextField, BorderLayout.CENTER); frame.add(datePanel, BorderLayout.NORTH); frame.add(new JTextField(), BorderLayout.SOUTH); frame.setSize(250, 100);//from w w w. j ava 2 s. c o m frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JFrame aWindow = new JFrame("This is a Box Layout"); aWindow.setBounds(200, 200, 200, 200); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Box left = Box.createVerticalBox(); left.add(Box.createVerticalStrut(30)); ButtonGroup radioGroup = new ButtonGroup(); JRadioButton rbutton;/*from w ww .j a v a 2s.c om*/ radioGroup.add(rbutton = new JRadioButton("Red")); left.add(rbutton); left.add(Box.createVerticalStrut(30)); radioGroup.add(rbutton = new JRadioButton("Green")); left.add(rbutton); left.add(Box.createVerticalStrut(30)); radioGroup.add(rbutton = new JRadioButton("Blue")); left.add(rbutton); left.add(Box.createVerticalStrut(30)); radioGroup.add(rbutton = new JRadioButton("Yellow")); left.add(rbutton); left.add(Box.createGlue()); JPanel leftPanel = new JPanel(new BorderLayout()); leftPanel.setBorder(new TitledBorder(new EtchedBorder(), "Line Color")); leftPanel.add(left, BorderLayout.CENTER); Box right = Box.createVerticalBox(); right.add(Box.createVerticalStrut(30)); right.add(new JCheckBox("Dashed")); right.add(Box.createVerticalStrut(30)); right.add(new JCheckBox("Thick")); right.add(Box.createVerticalStrut(30)); right.add(new JCheckBox("Rounded")); right.add(Box.createGlue()); JPanel rightPanel = new JPanel(new BorderLayout()); rightPanel.setBorder(new TitledBorder(new EtchedBorder(), "Line Properties")); rightPanel.add(right, BorderLayout.CENTER); Box top = Box.createHorizontalBox(); top.add(leftPanel); top.add(Box.createHorizontalStrut(5)); top.add(rightPanel); Container content = aWindow.getContentPane(); content.setLayout(new BorderLayout()); content.add(top, BorderLayout.CENTER); BoxLayout box = new BoxLayout(content, BoxLayout.Y_AXIS); content.setLayout(box); content.add(top); aWindow.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = (JPanel) frame.getContentPane(); panel.setLayout(new BorderLayout()); JTextField field = new JTextField(20); Main spinner = new Main(); panel.add(field, "Center"); panel.add(spinner, "East"); Dimension dim = frame.getToolkit().getScreenSize(); frame.setLocation(dim.width / 2 - frame.getWidth() / 2, dim.height / 2 - frame.getHeight() / 2); frame.pack();/*from w w w.j a va2 s. c om*/ frame.show(); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Label Focus Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); label.setLabelFor(textField);//from w w w.j av a2 s . c o m panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String arg[]) { JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); JPanel gb = new JPanel(new GridBagLayout()); JLabel content = new JLabel("Some text"); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.NORTH; gbc.weighty = 1;// ww w. j a v a2 s . c om gb.add(content, gbc); // gbc is containing the GridBagConstraints frame.add(gb, BorderLayout.CENTER); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); label.setLabelFor(textField);// ww w.java 2s .c o m panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel, BorderLayout.NORTH); frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); final JLabel valueLabel = new JLabel(String.valueOf(value)); JButton decButton = new JButton("-"); decButton.addActionListener(e -> valueLabel.setText(String.valueOf(--value))); JButton incButton = new JButton("+"); incButton.addActionListener(e -> valueLabel.setText(String.valueOf(++value))); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1;/*w ww . ja v a 2s . c o m*/ c.gridx = 0; c.gridy = 0; panel.add(decButton, c); c.gridx = 1; panel.add(valueLabel, c); c.gridx = 2; panel.add(incButton, c); c.gridy = 1; int w = 32; for (c.gridx = 0; c.gridx < 3; c.gridx++) { panel.add(Box.createHorizontalStrut(w), c); } frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); label.setLabelFor(textField);// w ww .j ava 2 s . c o m panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Label Focus Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); label.setLabelFor(textField);/* w w w .ja v a 2 s .c om*/ panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); frame.setSize(250, 150); frame.setVisible(true); textField.setText("Loooooooooooooooooooooooooooooooooooooooooooooooooooooooong"); BoundedRangeModel model = textField.getHorizontalVisibility(); int extent = model.getExtent(); textField.setScrollOffset(extent); System.out.println("extent:" + extent); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout(5, 5)); int sz = 4;//from ww w. ja v a 2 s . com Container content = new JPanel(new GridLayout(sz, 0, 2, 2)); for (int f = 0; f < sz * sz; f++) { content.add(new JButton()); } gui.add(content, BorderLayout.CENTER); Container info = new JPanel(new FlowLayout(FlowLayout.CENTER, 50, 5)); info.add(new JLabel("Flow")); info.add(new JLabel("Layout")); gui.add(info, BorderLayout.PAGE_START); gui.add(new JLabel("Label"), BorderLayout.LINE_END); JOptionPane.showMessageDialog(null, gui); }