List of usage examples for javax.swing JFrame pack
@SuppressWarnings("deprecation") public void pack()
From source file:Main.java
public static void main(String argv[]) throws Exception { JComboBox<Item> comboBox = new JComboBox<Item>( new Item[] { new Item("Major", "red"), new Item("Critical", "dark"), new Item("Minor", "green") }); comboBox.addActionListener(e -> { JComboBox<Item> combo = (JComboBox<Item>) e.getSource(); Item item = (Item) combo.getSelectedItem(); System.out.println(item.getColor()); });/* w w w. java 2 s .c om*/ JFrame frame = new JFrame(); frame.add(comboBox); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new Main(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true);/*from ww w .j a v a 2 s . c om*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFileChooser chooser = new JFileChooser(); File file = new File("filename.txt"); Icon icon = chooser.getIcon(file); JLabel label = new JLabel("" + file); label.setIcon(icon);//from w w w.jav a 2 s .c o m JFrame frame = new JFrame(); frame.getContentPane().add(label, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { File f = new File("your.ttf"); FileInputStream in = new FileInputStream(f); Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, in); Font dynamicFont32Pt = dynamicFont.deriveFont(32f); JLabel testLabel = new JLabel(dynamicFont.getName()); testLabel.setFont(dynamicFont32Pt);//from w w w . j a v a 2 s . com JFrame frame = new JFrame("Font Loading Demo"); frame.getContentPane().add(testLabel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new Main(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true);//from ww w . j a va 2 s. c o m }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { JFrame frame = new JFrame(); frame.add(new JLabel("Minimize demo")); frame.pack(); // Show the frame frame.setVisible(true);/*from w ww.j ava2s . c o m*/ // Sleep for 5 seconds, then minimize Thread.sleep(5000); frame.setState(Frame.ICONIFIED); // Sleep for 5 seconds, then restore Thread.sleep(5000); frame.setState(Frame.NORMAL); // Sleep for 5 seconds, then kill window Thread.sleep(5000); frame.setVisible(false); frame.dispose(); // Terminate test System.exit(0); }
From source file:JTextAreaI18N.java
public static void main(String[] args) { JFrame frame = new JTextAreaI18N(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true);// w ww . ja v a 2 s . c o m }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new Main(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true);/*from w ww . j a v a2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { File f = new File("your.ttf"); FileInputStream in = new FileInputStream(f); Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, in); Font dynamicFont32Pt = dynamicFont.deriveFont(32f); JLabel testLabel = new JLabel("Dynamically loaded font \"" + dynamicFont.getName() + "\""); testLabel.setFont(dynamicFont32Pt);//from www . java 2s.c o m JFrame frame = new JFrame("Font Loading Demo"); frame.getContentPane().add(testLabel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { Object[][] data = { { "A", new Integer(3), new Double(7.23), new Boolean(true) }, { "J", new Integer(2), new Double(4.64), new Boolean(false) }, { "S", new Integer(1), new Double(8.81), new Boolean(true) } }; String[] columns = { "Col", "Col", "Col", "Col" }; JTable table = new JTable(data, columns); JScrollPane scroll = new JScrollPane(table); JFrame f = new JFrame(); f.setContentPane(scroll);/*from w ww . j a va 2 s. c o m*/ f.pack(); int x = (int) table.getTableHeader().getSize().getWidth(); int y = (int) table.getTableHeader().getSize().getHeight() + (int) table.getSize().getHeight(); BufferedImage bi = new BufferedImage((int) x, (int) y, BufferedImage.TYPE_INT_RGB); Graphics g = bi.createGraphics(); table.getTableHeader().paint(g); g.translate(0, table.getTableHeader().getHeight()); table.paint(g); g.dispose(); JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(bi))); ImageIO.write(bi, "png", new File("c:/Java_Dev/table.png")); System.exit(0); }