List of usage examples for javax.swing JFrame add
public Component add(Component comp)
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Button"); frame.add(button); frame.setAlwaysOnTop(true);/*from w w w . j ava2 s.co m*/ frame.setSize(500, 500); frame.setLocation(500, 500); button.addActionListener(e -> { JOptionPane optionPane = new JOptionPane("Option Pane"); optionPane.showMessageDialog(frame, "Message!"); }); frame.setVisible(true); }
From source file:FormLayoutTester.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setLayout(new FormLayout()); frame.add(new JLabel("A")); frame.add(new JTextField(15)); frame.add(new JLabel("AA")); frame.add(new JTextField(20)); frame.add(new JLabel("AAAA")); frame.add(new JTextField(10)); frame.add(new JLabel("AAAAAA")); frame.add(new JTextField(2)); frame.add(new JLabel("AAAAAAAA")); frame.add(new JTextField(5)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack();/* w ww. j av a2s . com*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JCheckBox a = new JCheckBox("A"); a.setSelected(true);// w ww. j a va2 s . co m JCheckBox b = new JCheckBox("B"); JCheckBox c = new JCheckBox("C"); JCheckBox d = new JCheckBox("D"); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Car Features")); frame.add(a); frame.add(b); frame.add(c); frame.add(d); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(new BorderLayout()); f.add(new TestPane()); f.pack();//w ww.j av a 2 s.co m f.setVisible(true); }
From source file:SineDraw.java
public static void main(String[] args) { JPanel p = new Main(); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(p); frame.setSize(500, 500);// ww w.j a va 2s.c om frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.pack();/* w w w .j a v a 2 s . co m*/ frame.setVisible(true); System.out.println("Frame size = " + frame.getSize()); }
From source file:Main.java
public static void main(String[] args) { final JButton ok = new JButton("ok"); JCheckBox cb = new JCheckBox("Enabled", true); cb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (ok.isEnabled()) ok.setEnabled(false);/*from w w w . j av a2 s.co m*/ else ok.setEnabled(true); } }); ButtonModel model = new DefaultButtonModel() { public void setEnabled(boolean b) { if (b) System.out.println("Pressed: true"); else System.out.println("Pressed: false"); super.setEnabled(b); } public void setArmed(boolean b) { if (b) System.out.println("Armed: true"); else System.out.println("Armed: false"); super.setArmed(b); } public void setPressed(boolean b) { if (b) System.out.println("Pressed: true"); else System.out.println("Pressed: false"); super.setPressed(b); } }; ok.setModel(model); JFrame f = new JFrame(); f.setLayout(new FlowLayout()); f.add(ok); f.add(cb); f.setSize(350, 250); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JRadioButton button1 = new JRadioButton("Red"); JRadioButton button2 = new JRadioButton("Green"); JRadioButton button3 = new JRadioButton("Blue"); ButtonGroup colorButtonGroup = new ButtonGroup(); colorButtonGroup.add(button1);/*from ww w .j a v a2s . c o m*/ colorButtonGroup.add(button2); colorButtonGroup.add(button3); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Color:")); frame.add(button1); frame.add(button2); frame.add(button3); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("<html>bold <br> plain</html>"); frame.add(label); frame.setSize(300, 200);/*from w w w. j a v a2 s . c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(); JTextField tf1 = new JTextField(10); panel.add(tf1);/*from ww w . j av a2s .c o m*/ JTextField tf2 = new JTextField(10); panel.add(tf2); new TextPrompt("First Name", tf1); new TextPrompt("Last Name", tf2); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }