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 bottomPanel = new JPanel(); bottomPanel.add(new JButton("Bottom Button")); bottomPanel.setBorder(BorderFactory.createTitledBorder("Bottom Panel")); JPanel centerPanel = new JPanel(); centerPanel.setBorder(BorderFactory.createTitledBorder("Center Panel")); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(centerPanel, BorderLayout.CENTER); mainPanel.add(bottomPanel, BorderLayout.PAGE_END); int eb = 25;//from w ww.jav a 2 s .c om mainPanel.setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb)); mainPanel.setPreferredSize(new Dimension(500, 400)); JFrame frame = new JFrame("Main"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextPane textPane = new JTextPane(); textPane.setText("This is a test string"); StyleConstants.setBold(BOLD, true); StyleConstants.setItalic(ITALIC, true); int start = 5; int end = 10; textPane.getStyledDocument().setCharacterAttributes(start, end - start, BOLD, false); textPane.getStyledDocument().setCharacterAttributes(start, end - start, ITALIC, false); for (int i = start; i < end; i++) System.out.println(/* w ww . j a va 2s.c om*/ textPane.getStyledDocument().getCharacterElement(i).getAttributes().containsAttributes(BOLD)); // all now print true JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(textPane)); 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.pack(); Container contentPane = frame.getContentPane(); contentPane.setLayout(null);/* ww w. j a v a 2 s .com*/ for (int i = 0; i < 4; i++) { JPanel panel = new JPanel(); panel.setBounds((i * 75) + 475, 25, 75, 100); System.out.println(panel.getBounds()); contentPane.add(panel); panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 3)); } System.out.println(getComponentAt(contentPane, new Point(475, 25))); System.out.println(getComponentAt(contentPane, new Point(100, 25))); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("FormatDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new Main()); frame.pack(); frame.setVisible(true);/*from w ww. ja va 2s . co m*/ }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(new Main(frame)); frame.pack(); frame.setVisible(true);/* w ww . j a v a2 s . c o m*/ }
From source file:JapaneseCalendar.java
public static void main(String[] a) { JFrame f = new JFrame(); f.add(new JapaneseCalendar()); f.pack(); f.setVisible(true);//from ww w .j av a 2s . co m }
From source file:Main.java
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override/*from w w w .j av a2 s .c om*/ public void run() { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new MyPanel()); f.pack(); f.setVisible(true); } }); }
From source file:Main.java
public static void main(String[] args) { Object[] items = new Object[] { "Dog", "Cat", "Other" }; DefaultComboBoxModel dcbm = new DefaultComboBoxModel(items); JComboBox comboBox = new JComboBox(dcbm); comboBox.setPreferredSize(new Dimension(200, 20)); comboBox.addItemListener(e -> {/*w w w .j a v a 2s . co m*/ Object selectedItem = comboBox.getSelectedItem(); boolean editable = selectedItem instanceof String && ((String) selectedItem).equals("Other"); comboBox.setEditable(editable); }); comboBox.getEditor().addActionListener(e -> { Object newItem = comboBox.getEditor().getItem(); DefaultComboBoxModel d = (DefaultComboBoxModel) comboBox.getModel(); d.addElement(newItem); d.setSelectedItem(newItem); }); JPanel content = new JPanel(new FlowLayout()); content.add(new JLabel("Test:")); content.add(comboBox); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(content); frame.pack(); frame.setVisible(true); }
From source file:ArabicDigitsI18N.java
public static void main(String[] argv) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add("Center", new ArabicDigitsI18N()); frame.pack(); frame.setVisible(true);/*from ww w . ja va2 s .com*/ }
From source file:Main.java
public static void main(String[] args) { Main paintEg = new Main(); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(paintEg); frame.pack(); frame.setVisible(true);//from w w w . ja v a2s .c om }