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[]) { DefaultTableModel model;/* ww w .j a va 2s . com*/ JTable t = new JTable(model = new DefaultTableModel(0, 1)); for (int i = 0; i < 10; i++) { model.addRow(new Object[] { i }); } JButton removeSelected = new JButton("remove"); removeSelected.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int[] selectedRows = t.getSelectedRows(); for (int i = selectedRows.length - 1; i >= 0; i--) { model.removeRow(selectedRows[i]); ; } } }); JFrame f = new JFrame(); f.add(new JScrollPane(t)); f.add(removeSelected, BorderLayout.SOUTH); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout()); gui.setBorder(new EmptyBorder(2, 3, 2, 3)); JPanel textPanel = new JPanel(new BorderLayout(5, 5)); textPanel.add(new JScrollPane(new JTextArea("Top Text", 3, 20)), BorderLayout.PAGE_START); textPanel.add(new JScrollPane(new JTextArea("Main Text", 10, 10))); gui.add(textPanel, BorderLayout.CENTER); JPanel buttonCenter = new JPanel(new GridBagLayout()); buttonCenter.setBorder(new EmptyBorder(5, 5, 5, 5)); JPanel buttonPanel = new JPanel(new GridLayout(0, 1, 5, 5)); for (int ii = 1; ii < 6; ii++) { buttonPanel.add(new JButton("Button " + ii)); }/*from ww w . ja va2s . c om*/ buttonCenter.add(buttonPanel); gui.add(buttonCenter, BorderLayout.LINE_END); JFrame f = new JFrame("Demo"); f.add(gui); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setLocationByPlatform(true); f.pack(); f.setVisible(true); }
From source file:SwingProgressBarExample.java
public static void main(String args[]) { final SwingProgressBarExample it = new SwingProgressBarExample(); JFrame frame = new JFrame("Progress Bar Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(it);//from ww w . ja va 2 s .co m frame.pack(); frame.setVisible(true); for (int i = MY_MINIMUM; i <= MY_MAXIMUM; i++) { final int percent = i; try { SwingUtilities.invokeLater(new Runnable() { public void run() { it.updateBar(percent); } }); java.lang.Thread.sleep(100); } catch (InterruptedException e) { ; } } }
From source file:HelloWorldSwing.java
public static void main(String[] args) { JFrame frame = new JFrame("HelloWorldSwing"); final JLabel label = new JLabel("Hello World"); frame.getContentPane().add(label);/*from w w w . j a v a2s . co m*/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("Frame"); frame.add(Box.createRigidArea(new Dimension(400, 300))); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true);/*from ww w. j a va 2 s . c o m*/ JDialog dialog = new JDialog(frame, "Dialog", true); int condition = JPanel.WHEN_IN_FOCUSED_WINDOW; InputMap inputMap = ((JPanel) dialog.getContentPane()).getInputMap(condition); ActionMap actionMap = ((JPanel) dialog.getContentPane()).getActionMap(); String enter = "enter"; inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), enter); actionMap.put(enter, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); dialog.add(Box.createRigidArea(new Dimension(200, 200))); dialog.pack(); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); FieldComponent golfgame = new FieldComponent(); ((Component) golfgame).setFocusable(true); frame.getContentPane().add(golfgame); frame.pack(); frame.setVisible(true);/* w w w.ja va2 s . c o m*/ }
From source file:NumberViewer.java
public static void main(String[] args) { JFrame f = new JFrame("Number Viewer"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new NumberViewer()); f.pack(); f.setVisible(true);/* w w w . j a v a 2s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel() { @Override//from w ww .ja v a2 s .com public Dimension getPreferredSize() { return new Dimension(200, 200); } }; panel.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { System.out.println("Resized to " + e.getComponent().getSize()); } @Override public void componentMoved(ComponentEvent e) { System.out.println("Moved to " + e.getComponent().getLocation()); } }); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab("test", panel); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(tabbedPane); 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); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.pack(); frame.setVisible(true);/*from w ww . j a v a 2s . c om*/ }
From source file:AreaSubtracting.java
public static void main(String arg[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add("Center", new AreaSubtracting()); frame.pack(); frame.setSize(new Dimension(400, 300)); frame.setVisible(true);/*from w ww . j a va 2s. c om*/ }