List of usage examples for javax.swing JFrame setSize
public void setSize(int width, int height)
The width and height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize .
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setSize(450, 250); JTable table = new JTable(5, 5); TableColumn testColumn = table.getColumnModel().getColumn(0); JComboBox<String> comboBox = new JComboBox<>(); comboBox.addItem("This"); comboBox.addItem("is"); comboBox.addItem("a"); comboBox.addItem("Sample program"); testColumn.setCellEditor(new DefaultCellEditor(comboBox)); frame.add(table);// ww w .jav a2 s . c o m frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new Main()); frame.setVisible(true);//from ww w . j a va2 s. c om }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addRow(new Object[] { "r1" }); model.addRow(new Object[] { "r2" }); model.addRow(new Object[] { "r3" }); Vector data = model.getDataVector(); Vector row = (Vector) data.elementAt(1); // Overwrite the first row with the copy Vector firstRow = (Vector) data.elementAt(0); for (int i = 0; i < row.size(); i++) { firstRow.set(i, row.get(i));//from w w w . j av a 2 s. c o m } JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JButton jbtnA = new JButton("java2s.com"); JFrame jfrm = new JFrame(); jfrm.setSize(300, 300); jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jfrm.getRootPane().setDefaultButton(jbtnA); jbtnA.setMnemonic(KeyEvent.VK_A); jbtnA.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { System.out.println("Alpha pressed. Beta is enabled."); jbtnA.setEnabled(!jbtnA.isEnabled()); }/*from w w w . ja va2 s.co m*/ }); jfrm.add(jbtnA); jfrm.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) { JTextField component = new JTextField(10); component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("typed X"), "none"); JFrame f = new JFrame(); f.add(component);// w w w.j a va 2 s.c o m f.setSize(300, 300); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("Tool Tip Demo"); frame.setSize(200, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Hover on me!"); label.setToolTipText("My JLabel Tool Tip"); frame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER)); frame.getContentPane().add(label);/* w w w .ja v a 2 s . co m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setTitle("System LAF Demo"); try {//from w ww .j a v a2 s . com UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (UnsupportedLookAndFeelException e) { e.printStackTrace(); } SwingUtilities.updateComponentTreeUI(frame); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addRow(new Object[] { "r1" }); model.addRow(new Object[] { "r2" }); model.addRow(new Object[] { "r3" }); Vector data = model.getDataVector(); Vector row = (Vector) data.elementAt(1); // Copy the first column int mColIndex = 0; List colData = new ArrayList(table.getRowCount()); for (int i = 0; i < table.getRowCount(); i++) { row = (Vector) data.elementAt(i); colData.add(row.get(mColIndex)); }/*from w w w .j av a 2 s . c om*/ JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(800, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); device.setFullScreenWindow(frame);/*from w w w.j a v a2s .co m*/ device.setDisplayMode(new DisplayMode(800, 600, 32, 60)); frame.setVisible(true); JButton btn = new JButton(); btn.setText("Button"); JPanel panel = new JPanel(); panel.add(btn); frame.add(panel); btn.addActionListener(e -> { JOptionPane.showMessageDialog(frame.getContentPane(), "JOptionPane"); }); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 300); JPanel panel = new JPanel(new GridLayout(3, 1)); JLabel label = new JLabel(); JTextField tf = new JTextField(); JButton b = new JButton("calc sting width"); b.addActionListener(e -> {/* w w w . j a v a2s .c om*/ FontMetrics fm = label.getFontMetrics(label.getFont()); String text = tf.getText(); int textWidth = fm.stringWidth(text); label.setText("text width for \"" + text + "\": " + textWidth); }); panel.add(label); panel.add(tf); panel.add(b); frame.setContentPane(panel); frame.setVisible(true); }