List of usage examples for javax.swing JFrame dispose
public void dispose()
From source file:Main.java
public static void main(String[] args) { JButton close = new JButton("Close me programmatically"); final JFrame f = new JFrame("Close Me"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setContentPane(close);//from w w w .j a v a 2 s.c o m close.addActionListener(e -> { f.dispose(); }); f.pack(); f.setLocationByPlatform(true); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setVisible(true);/*from w ww. j a v a 2 s.com*/ String message = JOptionPane.showInputDialog(frame, "Would this be enough?.", "My dialog asks....", JOptionPane.INFORMATION_MESSAGE); System.out.println("Got " + message); frame.dispose(); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JLabel("Auto Hide")); frame.pack();/* w ww . j av a2 s . c o m*/ frame.setVisible(true); Timer autoHideTimer = new Timer(1000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { frame.dispose(); } }); autoHideTimer.setRepeats(false); frame.addMouseListener(new MouseAdapter() { @Override public void mouseExited(MouseEvent e) { System.out.println("Restart..."); autoHideTimer.restart(); } @Override public void mouseEntered(MouseEvent e) { System.out.println("Stop"); autoHideTimer.stop(); } }); }
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();//w w w.ja v a2 s . co m // Show the frame frame.setVisible(true); // 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:Main.java
public static void main(String[] args) { final JFrame frame = new JFrame("Test"); KeyboardFocusManager.getCurrentKeyboardFocusManager().addVetoableChangeListener("focusedWindow", new VetoableChangeListener() { private boolean gained = false; @Override//from www . j a v a2s. c o m public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException { if (evt.getNewValue() == frame) { gained = true; } if (gained && evt.getNewValue() != frame) { frame.dispose(); } } }); frame.add(new JTextField(10), BorderLayout.NORTH); frame.add(new JTextField(10), BorderLayout.SOUTH); frame.pack(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:net.redstonelamp.gui.RedstoneLampGUI.java
public static void main(String[] args) { JFrame frame = new JFrame("RedstoneLamp"); frame.setLayout(new GridLayout(2, 1)); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JLabel label = new JLabel("RedstoneLamp"); label.setHorizontalAlignment(SwingConstants.CENTER); frame.add(label);/*from w w w . j a va 2 s . com*/ JPanel lowPanel = new JPanel(); JPanel left = new JPanel(); left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS)); lowPanel.add(left); JPanel right = new JPanel(); right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS)); lowPanel.add(right); JButton openButton = new JButton("Open server at..."); openButton.addActionListener(e -> { JFileChooser chooser = new JFileChooser(new File(".")); chooser.setDialogTitle("Select RedstoneLamp server home"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); int action = chooser.showOpenDialog(frame); if (action == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); File jar = new File("RedstoneLamp.jar"); if (!jar.isFile()) { int result = JOptionPane.showConfirmDialog(frame, "Could not find RedstoneLamp installation. " + "Would you like to install RedstoneLamp there?"); if (result == JOptionPane.YES_OPTION) { installCallback(frame, selected); } return; } frame.dispose(); addHistory(selected); currentRoot = new ServerActivity(selected); } }); right.add(openButton); JButton installButton = new JButton("Install server at..."); installButton.addActionListener(e -> { JFileChooser chooser = new JFileChooser("."); chooser.setDialogTitle("Select directory to install server in"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); int action = chooser.showSaveDialog(frame); if (action == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); File jar = new File("RedstoneLamp.jar"); if (jar.isFile()) { int result = JOptionPane.showConfirmDialog(frame, "A RedstoneLamp jar installation is present. " + "Are you sure you want to reinstall RedstoneLamp there?"); if (result == JOptionPane.NO_OPTION) { frame.dispose(); addHistory(selected); currentRoot = new ServerActivity(selected); return; } } installCallback(frame, selected); } }); frame.add(lowPanel); frame.pack(); Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation(dimension.width / 2 - frame.getSize().width / 2, dimension.height / 2 - frame.getSize().height / 2); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { final JFrame jf = new JFrame("JIFrameDemo Main Window"); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); screenSize.width -= 42;/*from ww w.ja v a 2 s . c o m*/ screenSize.height -= 42; jf.setSize(screenSize); jf.setLocation(20, 20); JMenuBar mb = new JMenuBar(); jf.setJMenuBar(mb); JMenu fm = new JMenu("File"); mb.add(fm); JMenuItem mi; fm.add(mi = new JMenuItem("Exit")); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); JDesktopPane dtp = new JDesktopPane(); //dtp.setBackground(Color.GREEN); jf.setContentPane(dtp); JInternalFrame mboxFrame = new JInternalFrame("Mail Reader", true, true, true, true); JLabel reader = new JLabel("Mail Reader Would Be Here"); mboxFrame.setContentPane(reader); mboxFrame.setSize(400, 300); mboxFrame.setLocation(50, 50); mboxFrame.setVisible(true); dtp.add(mboxFrame); JInternalFrame compFrame = new JInternalFrame("Compose Mail", true, true, true, true); JLabel composer = new JLabel("Mail Compose Would Be Here"); compFrame.setContentPane(composer); compFrame.setSize(300, 200); compFrame.setLocation(200, 200); compFrame.setVisible(true); dtp.add(compFrame); JInternalFrame listFrame = new JInternalFrame("Users", true, true, true, true); JLabel list = new JLabel("List of Users Would Be Here"); listFrame.setContentPane(list); listFrame.setLocation(400, 400); listFrame.setSize(500, 200); listFrame.setVisible(true); dtp.add(listFrame); jf.setVisible(true); jf.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { jf.setVisible(false); jf.dispose(); System.exit(0); } }); }
From source file:ch.admin.hermes.etl.load.HermesETLApplication.java
/** * Hauptprogramm/*w w w . ja va 2 s . c o m*/ * @param args Commandline Argumente */ public static void main(String[] args) { JFrame frame = null; try { // Crawler fuer Zugriff auf HERMES 5 Online Loesung initialiseren */ crawler = new HermesOnlineCrawler(); // CommandLine Argumente aufbereiten parseCommandLine(args); // Methoden Export (Variante Zuehlke) extrahieren System.out.println("load library " + model); ModelExtract root = new ModelExtract(); root.extract(model); frame = createProgressDialog(); // wird das XML Model von HERMES Online geholt - URL der Templates korrigieren if (scenario != null) { List<Workproduct> workproducts = (List<Workproduct>) root.getObjects().get("workproducts"); for (Workproduct wp : workproducts) for (Template t : wp.getTemplate()) { // Template beinhaltet kompletten URL - keine Aenderung if (t.getUrl().toLowerCase().startsWith("http") || t.getUrl().toLowerCase().startsWith("file")) continue; // Model wird ab Website geholte if (model.startsWith("http")) t.setUrl(crawler.getTemplateURL(scenario, t.getUrl())); // Model ist lokal - Path aus model und relativem Path Template zusammenstellen else { File m = new File(model); t.setUrl(m.getParentFile() + "/" + t.getUrl()); } } } // JavaScript - fuer Import in Fremdsystem if (script.endsWith(".js")) { final JavaScriptEngine js = new JavaScriptEngine(); js.setObjects(root.getObjects()); js.put("progress", progress); js.eval("function log( x ) { println( x ); progress.setString( x ); }"); progress.setString("call main() in " + script); js.put(ScriptEngine.FILENAME, script); js.call(new InputStreamReader(new FileInputStream(script)), "main", new Object[] { site, user, passwd }); } // FreeMarker - fuer Umwandlungen nach HTML else if (script.endsWith(".ftl")) { FileOutputStream out = new FileOutputStream( new File(script.substring(0, script.length() - 3) + "html ")); int i = script.indexOf("templates"); if (i >= 0) script = script.substring(i + "templates".length()); MethodTransform transform = new MethodTransform(); transform.transform(root.getObjects(), script, out); out.close(); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e.toString(), "Fehlerhafte Verarbeitung", JOptionPane.WARNING_MESSAGE); e.printStackTrace(); } if (frame != null) { frame.setVisible(false); frame.dispose(); } System.exit(0); }
From source file:Main.java
/** * Schedule disposal of a frame (async). *//*from w w w .ja v a2 s .com*/ public static void dispose(final JFrame frame) { SwingUtilities.invokeLater(new Runnable() { public void run() { if (frame.isDisplayable()) frame.dispose(); } }); }
From source file:Main.java
public static void closeOnEscape(final JFrame frame) { KeyStroke stroke = KeyStroke.getKeyStroke("ESCAPE"); Action actionListener = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { frame.setVisible(false);//from w w w . j ava2 s.c om frame.dispose(); } }; JRootPane rootPane = frame.getRootPane(); InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(stroke, "ESCAPE"); rootPane.getActionMap().put("ESCAPE", actionListener); }