List of usage examples for javax.swing JFrame show
@Deprecated public void show()
From source file:SpinnerTest.java
public static void main(String args[]) { JFrame frame = new JFrame("Spinning"); Container contentPane = frame.getContentPane(); String months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; SpinnerModel model = new SpinnerListModel(months); JSpinner spinner = new JSpinner(model); contentPane.add(spinner, BorderLayout.NORTH); SpinnerDateModel model2 = new SpinnerDateModel(); model2.setCalendarField(Calendar.WEEK_OF_MONTH); JSpinner spinner2 = new JSpinner(model2); JSpinner.DateEditor editor2 = new JSpinner.DateEditor(spinner2, "MMMMM dd, yyyy"); spinner2.setEditor(editor2);//ww w . j a v a 2 s . c o m frame.getContentPane().add(spinner2, BorderLayout.CENTER); SpinnerNumberModel model3 = new SpinnerNumberModel(50, 0, 100, 5); JSpinner spinner3 = new JSpinner(model3); frame.getContentPane().add(spinner3, BorderLayout.SOUTH); frame.setSize(200, 100); frame.show(); }
From source file:WindowTest.java
public static void main(String args[]) { JFrame frame = new JFrame("Window Listener"); WindowListener listener = new WindowListener() { public void windowActivated(WindowEvent w) { System.out.println(w); }//from ww w . ja v a2 s .co m public void windowClosed(WindowEvent w) { System.out.println(w); } public void windowClosing(WindowEvent w) { System.out.println(w); System.exit(0); } public void windowDeactivated(WindowEvent w) { System.out.println(w); } public void windowDeiconified(WindowEvent w) { System.out.println(w); } public void windowIconified(WindowEvent w) { System.out.println(w); } public void windowOpened(WindowEvent w) { System.out.println(w); } }; frame.addWindowListener(listener); frame.setSize(300, 300); frame.show(); }
From source file:AdjustmentTest.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); Icon icon = new ImageIcon("java2s.gif"); JButton b = new JButton(icon); JScrollPane pane = new JScrollPane(b); AdjustmentListener hListener = new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { System.out.println("Horizontal: "); dumpInfo(e);/*from w w w . j av a 2 s . c om*/ } }; JScrollBar hBar = pane.getHorizontalScrollBar(); hBar.addAdjustmentListener(hListener); AdjustmentListener vListener = new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { System.out.println("Vertical: "); dumpInfo(e); } }; JScrollBar vBar = pane.getVerticalScrollBar(); vBar.addAdjustmentListener(vListener); contentPane.add(pane, BorderLayout.CENTER); frame.setSize(300, 200); frame.show(); }
From source file:MovingIconTest.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); JButton b;/* www.ja va2 s.co m*/ Icon icon = new PieIcon(Color.red); b = new JButton("Default", icon); contentPane.add(b, BorderLayout.NORTH); b = new JButton("Text Left", icon); b.setHorizontalTextPosition(JButton.LEFT); contentPane.add(b, BorderLayout.SOUTH); b = new JButton("Text Up", icon); b.setHorizontalTextPosition(JButton.CENTER); b.setVerticalTextPosition(JButton.TOP); contentPane.add(b, BorderLayout.EAST); b = new JButton("Text Down", icon); b.setHorizontalTextPosition(JButton.CENTER); b.setVerticalTextPosition(JButton.BOTTOM); contentPane.add(b, BorderLayout.WEST); b = new JButton("Align Bottom Left", icon); b.setHorizontalAlignment(JButton.LEFT); b.setVerticalAlignment(JButton.BOTTOM); contentPane.add(b, BorderLayout.CENTER); frame.setSize(300, 200); frame.show(); }
From source file:GridBagWithGridWidthHeight.java
public static void main(String[] args) { JFrame f = new JFrame("Demonstrates the use of gridwidth, gridheight constraints"); JPanel p = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 2, 2); c.weighty = 1.0;//from w w w. j a va2 s . c om c.weightx = 1.0; c.gridx = 0; c.gridy = 0; c.gridheight = 2; // span across 2 rows p.add(new JButton("Java"), c); c.gridx = 1; c.gridheight = 1; // set back to 1 row c.gridwidth = 2; // span across 2 columns p.add(new JButton("Source"), c); c.gridy = 1; c.gridwidth = 1; // set back to 1 column p.add(new JButton("and"), c); c.gridx = 2; p.add(new JButton("Support."), c); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; f.addWindowListener(wndCloser); f.getContentPane().add(p); f.setSize(600, 200); f.show(); }
From source file:DateTimeEditor.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = (JPanel) frame.getContentPane(); panel.setLayout(new BorderLayout()); JTextField field = new JTextField(20); Spinner spinner = new Spinner(); panel.add(field, "Center"); panel.add(spinner, "East"); Dimension dim = frame.getToolkit().getScreenSize(); frame.setLocation(dim.width / 2 - frame.getWidth() / 2, dim.height / 2 - frame.getHeight() / 2); frame.pack();/*ww w . ja v a2 s . c o m*/ frame.show(); }
From source file:PopupTest.java
public static void main(String args[]) { JFrame frame = new JFrame("Popup Menu Listener"); Container contentPane = frame.getContentPane(); final String flavors[] = { "Item 1", "Item 2", "Item 3" }; PopupMenuListener listener = new PopupMenuListener() { boolean initialized = false; public void popupMenuCanceled(PopupMenuEvent e) { }/*w w w . ja va 2 s . co m*/ public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } public void popupMenuWillBecomeVisible(PopupMenuEvent e) { if (!initialized) { JComboBox combo = (JComboBox) e.getSource(); ComboBoxModel model = new DefaultComboBoxModel(flavors); combo.setModel(model); initialized = true; } } }; JComboBox jc = new JComboBox(); jc.addPopupMenuListener(listener); jc.setMaximumRowCount(4); jc.setEditable(true); contentPane.add(jc, BorderLayout.NORTH); frame.pack(); frame.show(); }
From source file:GridBagWithAnchor.java
public static void main(String[] args) { JFrame f = new JFrame("Demonstrates the use of anchor constraints"); JPanel p = new JPanel(new GridBagLayout()); p.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 2, 2); c.weighty = 1.0;/*from w ww. j a v a 2 s. com*/ c.weightx = 1.0; c.gridx = 0; c.gridy = 0; c.gridheight = 2; c.anchor = GridBagConstraints.NORTH; // place component on the North p.add(new JButton("Java"), c); c.gridx = 1; c.gridheight = 1; c.gridwidth = 2; c.anchor = GridBagConstraints.SOUTHWEST; p.add(new JButton("Source"), c); c.gridy = 1; c.gridwidth = 1; c.anchor = GridBagConstraints.CENTER; // remember to rest to center p.add(new JButton("and"), c); c.gridx = 2; p.add(new JButton("Support !!!"), c); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; f.addWindowListener(wndCloser); f.getContentPane().add(p); f.setSize(600, 200); f.show(); }
From source file:GridBagWithWeight.java
public static void main(String[] args) { JFrame f = new JFrame("Demonstrates the use of fill constraints"); JPanel p = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 2, 2); c.weighty = 1.0;// w w w . j a va 2 s . c om c.weightx = 1.0; c.gridx = 0; c.gridy = 0; c.gridheight = 2; c.fill = GridBagConstraints.BOTH; // Use both horizontal & vertical p.add(new JButton("Java"), c); c.gridx = 1; c.gridheight = 1; c.gridwidth = 2; c.fill = GridBagConstraints.HORIZONTAL; // Horizontal only p.add(new JButton("Source"), c); c.gridy = 1; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; // Remember to reset to none p.add(new JButton("and"), c); c.gridx = 2; c.fill = GridBagConstraints.VERTICAL; // Vertical only p.add(new JButton("Support."), c); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; f.addWindowListener(wndCloser); f.getContentPane().add(p); f.setSize(600, 200); f.show(); }
From source file:GridBagWithContaints.java
public static void main(String[] args) { JFrame f = new JFrame("Demonstrates the use of gridx, gridy,ipadx, ipady and insets constraints"); JPanel p = new JPanel(); p.setLayout(new GridBagLayout()); // creates a constraints object GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 2, 2); // insets for all components c.gridx = 0; // column 0 c.gridy = 0; // row 0 c.ipadx = 5; // increases components width by 10 pixels c.ipady = 5; // increases components height by 10 pixels p.add(new JButton("Java"), c); // constraints passed in c.gridx = 1; // column 1 // c.gridy = 0; // comment out this for reusing the obj c.ipadx = 0; // resets the pad to 0 c.ipady = 0;/*from ww w . j a va 2s . co m*/ p.add(new JButton("Source"), c); c.gridx = 0; // column 0 c.gridy = 1; // row 1 p.add(new JButton("and"), c); c.gridx = 1; // column 1 p.add(new JButton("Support."), c); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; f.addWindowListener(wndCloser); f.getContentPane().add(p); f.setSize(600, 200); f.show(); }