List of usage examples for javax.swing JFrame pack
@SuppressWarnings("deprecation") public void pack()
From source file:Main.java
public static void main(String[] args) { Vector<Double> doubleVector = new Vector<Double>(); Vector<Integer> integerVector = new Vector<Integer>(); Vector<Boolean> booleanVector = new Vector<Boolean>(); Vector<Icon> iconVector = new Vector<Icon>(); Icon icon1 = ((UIManager.getIcon("OptionPane.errorIcon"))); Icon icon2 = (UIManager.getIcon("OptionPane.informationIcon")); Icon icon3 = (UIManager.getIcon("OptionPane.warningIcon")); Icon icon4 = (UIManager.getIcon("OptionPane.questionIcon")); doubleVector.addElement(1.001);/*w ww . j a va2 s . c om*/ doubleVector.addElement(10.00); doubleVector.addElement(0.95); doubleVector.addElement(4.2); JComboBox comboBoxDouble = new JComboBox(doubleVector); integerVector.addElement(1); integerVector.addElement(2); integerVector.addElement(3); integerVector.addElement(4); JComboBox comboBoxInteger = new JComboBox(integerVector); booleanVector.add(Boolean.TRUE); booleanVector.add(Boolean.FALSE); JComboBox comboBoxBoolean = new JComboBox(booleanVector); iconVector.addElement(icon1); iconVector.addElement(icon2); iconVector.addElement(icon3); iconVector.addElement(icon4); JComboBox comboBoxIcon = new JComboBox(iconVector); JFrame frame = new JFrame(); frame.setLayout(new GridLayout(2, 2, 5, 5)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(comboBoxDouble); frame.add(comboBoxInteger); frame.add(comboBoxBoolean); frame.add(comboBoxIcon); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(Main.class.getSimpleName()); DefaultTreeModel model = getTreeModel(); JTree tree1 = new JTree(model); JTree tree2 = new JTree(model); frame.add(new JScrollPane(tree1), BorderLayout.WEST); frame.add(new JScrollPane(tree2), BorderLayout.EAST); frame.pack(); frame.setSize(frame.getWidth() + 50, frame.getHeight() + 140); frame.setVisible(true);/* www. j a v a 2s .c om*/ Timer t = new Timer(2000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); root.add(new DefaultMutableTreeNode("A new node")); model.nodesWereInserted(root, new int[] { root.getChildCount() - 1 }); tree1.expandRow(0); tree2.expandRow(0); frame.revalidate(); } }); t.start(); }
From source file:TextForm.java
public static void main(String[] args) { String[] labels = { "First Name", "Middle Initial", "Last Name", "Age" }; char[] mnemonics = { 'F', 'M', 'L', 'A' }; int[] widths = { 15, 1, 15, 3 }; String[] descs = { "First Name", "Middle Initial", "Last Name", "Age" }; final TextForm form = new TextForm(labels, mnemonics, widths, descs); JButton submit = new JButton("Submit Form"); submit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(form.getText(0) + " " + form.getText(1) + ". " + form.getText(2) + ", age " + form.getText(3));/*w ww.j a va2s . com*/ } }); JFrame f = new JFrame("Text Form Example"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(form, BorderLayout.NORTH); JPanel p = new JPanel(); p.add(submit); f.getContentPane().add(p, BorderLayout.SOUTH); f.pack(); f.setVisible(true); }
From source file:AreaAdd.java
public static void main(String s[]) { JFrame f = new JFrame("Pear"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);//from ww w . j av a 2s . co m } }); JApplet applet = new AreaAdd(); f.getContentPane().add("Center", applet); applet.init(); f.pack(); f.setSize(new Dimension(150, 200)); f.show(); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); // Add a close button JButton closeButton = new JButton("Close"); contentPane.add(closeButton);//from w w w . j av a 2s.c om closeButton.addActionListener(e -> System.exit(0)); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); String s = "The quick brown fox jumps over the lazy dog!"; Font font = new Font(Font.SERIF, Font.PLAIN, 24); JLabel l1 = new MyLabel(s); l1.setFont(font);// www . j a va2 s. c om f.setContentPane(l1); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Add a close button JButton closeButton = new JButton("Close"); Container contentPane = frame.getContentPane(); contentPane.add(closeButton);/*from ww w .j a va2s. c o m*/ // Calculates and sets appropriate size for the frame frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JTextPane tp = new JTextPane(); JButton withFocus = new JButton("Select with focus"); withFocus.addActionListener(e -> { tp.selectAll();//w ww . j a v a2 s. co m tp.requestFocus(); }); JButton withOutFocus = new JButton("Select without focus"); withFocus.addActionListener(e -> tp.selectAll()); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(tp)); JPanel panel = new JPanel(); panel.add(withFocus); panel.add(withOutFocus); frame.add(panel, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:FilledArc.java
public static void main(String s[]) { JFrame f = new JFrame(""); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);//from w ww. j av a 2s .c o m } }); JApplet applet = new FilledArc(); f.getContentPane().add("Center", applet); applet.init(); f.pack(); f.setSize(new Dimension(300, 300)); f.show(); }
From source file:AreaIntersect.java
public static void main(String s[]) { JFrame f = new JFrame("Pear"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);//from ww w . ja v a 2s .c o m } }); JApplet applet = new AreaIntersect(); f.getContentPane().add("Center", applet); applet.init(); f.pack(); f.setSize(new Dimension(150, 200)); f.show(); }