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) { JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(800, 600)); String test[] = { "alpha", "bravo", "charlie", "delta", "echo", "omega", "zeta" }; JList<String> list = new JList<>(test); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setLayoutOrientation(JList.VERTICAL); list.setVisibleRowCount(5);/*from w ww . jav a 2s .com*/ list.setBounds(50, 150, 75, 90); JScrollPane jScrollPane1 = new JScrollPane(); jScrollPane1.setViewportView(list); panel.add(jScrollPane1); JFrame f = new JFrame(); f.add(panel); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setResizable(false); f.setFocusable(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File(args[0]); sun.awt.shell.ShellFolder sf = sun.awt.shell.ShellFolder.getShellFolder(file); Icon icon = new ImageIcon(sf.getIcon(true)); System.out.println("type = " + sf.getFolderType()); JLabel label = new JLabel(icon); JFrame frame = new JFrame(); frame.getContentPane().add(label);/*from ww w. j av a2 s. c o m*/ frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Box box = Box.createVerticalBox(); for (int i = 1; i < 4; i++) { JPanel panel = new JPanel() { @Override/*from www .j a v a 2s .co m*/ public Dimension getMaximumSize() { return getPreferredSize(); } }; JLabel label1 = new JLabel("Label"); JLabel label2 = new JLabel(String.valueOf(i)); panel.add(label1); panel.add(label2); box.add(panel); } JFrame frame = new JFrame(); frame.add(box); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(new BorderLayout()); String[] values = new String[] { "One", "Two", "Three" }; JComboBox<String> comboBox = new JComboBox<>(values); panel.add(comboBox, BorderLayout.NORTH); JTextArea textArea = new JTextArea(2, 2); panel.add(textArea, BorderLayout.CENTER); JButton button = new JButton("Action"); button.addActionListener(new ActionListener() { @Override// ww w . ja va 2 s . com public void actionPerformed(ActionEvent e) { textArea.setText((String) comboBox.getSelectedItem()); comboBox.setSelectedIndex(0); } }); panel.add(button, BorderLayout.SOUTH); JFrame frame = new JFrame(); frame.add(panel); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JComboBox<String> box = new JComboBox<>(); box.addItem("One"); box.addItem("Two"); box.addItem("Three"); box.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { System.out.println(e.getItem()); }/* w w w . j a v a 2s.c o m*/ } }); JFrame frame = new JFrame(); frame.getContentPane().add(box); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.add(new Main()); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);//from w w w .ja va 2 s .c o m }
From source file:Main.java
public static void main(String[] args) { JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.setUI(new MetalTabbedPaneUI() { @Override//from ww w.j av a 2s. c o m protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) { int width = super.calculateTabWidth(tabPlacement, tabIndex, metrics); int extra = tabIndex * 50; return width + extra; } }); tabbedPane.addTab("JTable", new JScrollPane(new JTable(5, 5))); tabbedPane.addTab("JTree", new JScrollPane(new JTree())); tabbedPane.addTab("JSplitPane", new JSplitPane()); JPanel p = new JPanel(); p.add(tabbedPane); JFrame frame = new JFrame(); frame.setContentPane(p); frame.pack(); frame.setVisible(true); }
From source file:ImageTest.java
public static void main(String[] args) { JPanel panel = new JPanel(); ImageLabel label = new ImageLabel(new ImageIcon("images/reactor.png")); label.setLocation(29, 37);/*from w w w .j a v a2s .c o m*/ panel.add(label); JFrame frame = new JFrame(); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JFrame frame = new MainClass(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true);/*from w w w . j a va2s. c om*/ }
From source file:ImageTest.java
public static void main(String[] args) { ImagePanel panel = new ImagePanel(new ImageIcon("images/background.png").getImage()); JFrame frame = new JFrame(); frame.getContentPane().add(panel);// ww w . j ava 2 s . c om frame.pack(); frame.setVisible(true); }