List of usage examples for javax.swing JFrame addWindowListener
public synchronized void addWindowListener(WindowListener l)
From source file:EditorDropTarget4.java
public static void main(String[] args) { try {//from w w w . j a v a 2s .c om UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } final JFrame f = new JFrame("JEditor Pane Drop Target Example 4"); // Create an editor with autoscrolling support final JEditorPane pane = new AutoScrollingEditorPane(); // Add a drop target to the JEditorPane EditorDropTarget4 target = new EditorDropTarget4(pane); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); JPanel panel = new JPanel(); final JCheckBox editable = new JCheckBox("Editable"); editable.setSelected(true); panel.add(editable); editable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEditable(editable.isSelected()); } }); final JCheckBox enabled = new JCheckBox("Enabled"); enabled.setSelected(true); panel.add(enabled); enabled.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEnabled(enabled.isSelected()); } }); f.getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER); f.getContentPane().add(panel, BorderLayout.SOUTH); f.setSize(500, 400); f.setVisible(true); }
From source file:com.limegroup.gnutella.gui.notify.AnimatedWindow.java
public static void main(String[] args) { JPanel content = new JPanel(new BorderLayout()); content.setBorder(BorderFactory.createLineBorder(Color.black, 2)); JLabel label = new JLabel("Hello World"); label.setIcon(UIManager.getIcon("FileView.computerIcon")); label.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); content.add(label, BorderLayout.CENTER); final AnimatedWindow window = new AnimatedWindow(null); window.setFinalLocation(new Point(200, 200)); window.setContentPane(content);/*from ww w . j a v a 2 s . c om*/ JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 10)); JButton button = new JButton("Bottom -> Top"); buttonPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { window.setMode(AnimationMode.BOTTOM_TO_TOP); if (!window.isVisible() || window.isHideAnimationInProgress()) { window.doShow(); } else { window.doHide(); } } }); button = new JButton("Top -> Bottom"); buttonPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { window.setMode(AnimationMode.TOP_TO_BOTTOM); if (!window.isVisible() || window.isHideAnimationInProgress()) { window.doShow(); } else { window.doHide(); } } }); button = new JButton("Fade"); buttonPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { window.setMode(AnimationMode.FADE); if (!window.isVisible() || window.isHideAnimationInProgress()) { window.doShow(); } else { window.doHide(); } } }); JFrame app = new JFrame("AnimatedWindow Demo"); app.setContentPane(buttonPanel); app.pack(); app.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); app.setVisible(true); }
From source file:EditorPaneExample19.java
public static void main(String[] args) { try {// w w w .j a v a2 s . c om UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new EditorPaneExample19(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(500, 400); f.setVisible(true); }
From source file:GridBagWithWeight.java
public static void main(String[] args) { JFrame f = new JFrame("Demonstrates the use of weightx, weighty constraints"); JPanel p = new JPanel(); p.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); p.setLayout(new GridBagLayout()); c = new GridBagConstraints(); c.insets = new Insets(2, 2, 2, 2); c.weighty = 1.0;/*from w w w . j a v a 2 s . com*/ c.weightx = 1.0; c.gridx = 0; c.gridy = 0; p.add(new JButton("Java"), c); c.gridx = 1; p.add(new JButton("Source"), c); c.gridx = 0; c.gridy = 1; p.add(new JButton("and"), c); c.gridx = 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(); }
From source file:EditorPaneExample18.java
public static void main(String[] args) { try {/* www. j a v a 2s.c om*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new EditorPaneExample18(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(500, 400); f.setVisible(true); }
From source file:livecanvas.mesheditor.MeshEditor.java
public static void main(String[] args) throws Exception { // AlloyLookAndFeel.setProperty("alloy.licenseCode", // "2011/06/29#asidjoaisdjoasidjid@mailinator.com#lj8xv#1a193l"); // AlloyLookAndFeel.setProperty("alloy.isToolbarEffectsEnabled", // "false");//from ww w.j a v a 2 s. c om // try { // AlloyLookAndFeel alloyLnF = new AlloyLookAndFeel(); // alloyLnF.setTheme(new GlassTheme(), true); // UIManager.setLookAndFeel(alloyLnF); // } catch (UnsupportedLookAndFeelException ex) { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // } JFrame f = new JFrame("LiveCanvas - Mesh Editor"); final MeshEditor meshEditor = new MeshEditor(); f.setJMenuBar(meshEditor.getMenuBar()); f.getContentPane().add(meshEditor); f.getContentPane().add(meshEditor.getToolBar(), BorderLayout.NORTH); f.pack(); f.setLocationRelativeTo(null); f.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); // meshEditor.exit(); } }); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); f.setVisible(true); // meshEditor.open(new File("C:/Users/Jasleen/Desktop/prez.mesh")); }
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); }/* w ww . j a va 2 s. c o 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: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 ww w .j a va2 s . co m*/ 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:EditorPaneExample20.java
public static void main(String[] args) { try {//from w w w . ja v a 2 s. c o m UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new EditorPaneExample20(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(500, 400); f.setVisible(true); }
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;// w w w . j a va 2 s . co m 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(); }