List of usage examples for javax.swing JFrame dispose
public void dispose()
From source file:CheckThreadViolationRepaintManager.java
static void test() { JFrame frame = new JFrame("Am I on EDT?"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JButton("JButton")); frame.pack();//from w w w.j a v a 2 s. c o m frame.setVisible(true); frame.dispose(); }
From source file:Main.java
/** * Attaches a key event listener to given component, disposing of the given window * upon pressing escape within the context. * //from w ww . j a v a2s .c o m * @param context * @param button */ public static void simulateExitOnEscape(Component context, JFrame window) { context.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { for (WindowListener wl : window.getWindowListeners()) { wl.windowClosing(new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); } if (window != null) window.dispose(); } } }); }
From source file:edu.sdsc.scigraph.services.jersey.writers.ImageWriter.java
private static BufferedImage renderImage(JPanel panel) { JFrame frame = new JFrame(); frame.setUndecorated(true);//from w w w. j a v a 2 s .co m frame.getContentPane().add(panel); frame.pack(); BufferedImage bi = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = bi.createGraphics(); panel.print(graphics); graphics.dispose(); frame.dispose(); return bi; }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopComponentsHelper.java
/** * Determines real size of HTML label with text on screen. * * @param html text with html markup/*from w w w . jav a2 s . com*/ * @return size of label */ public static Dimension measureHtmlText(String html) { JFrame testFrame = new JFrame(); testFrame.setLayout(new BoxLayout(testFrame.getContentPane(), BoxLayout.PAGE_AXIS)); JLabel testLabel = new JLabel(html); testFrame.add(testLabel); testFrame.pack(); Dimension size = testLabel.getSize(); testFrame.dispose(); return new Dimension(size); }
From source file:osh.comdriver.simulation.cruisecontrol.ScheduleDrawer.java
public static void showScheduleAndWait(List<Schedule> schedules, HashMap<VirtualCommodity, PriceSignal> ps, HashMap<VirtualCommodity, PowerLimitSignal> pls, long currentTime) { final Object sync = new Object(); ScheduleDrawer demo = new ScheduleDrawer(schedules, ps, pls, currentTime); JFrame frame = new JFrame("Schedule"); frame.setContentPane(demo);/*from w w w .j av a2s .c o m*/ frame.pack(); RefineryUtilities.centerFrameOnScreen(frame); frame.setVisible(true); synchronized (sync) { try { sync.wait(); } catch (InterruptedException e) { } } frame.dispose(); }
From source file:levelBuilder.DialogMaker.java
/** * First window to interact with. Offers options of load graph or new graph. *//*from w ww .j ava 2 s . co m*/ private static void splashWindow() { final JFrame frame = new JFrame("Dialog Maker"); //Handles button pushes. class SplashActionHandler implements ActionListener { @Override public void actionPerformed(ActionEvent e) { frame.dispose(); if (e.getActionCommand().equals("loadGraph")) loadFilePopup(); else loadGraph(true); } } //Loads and sets background image. BufferedImage img = null; try { img = ImageIO.read(new File(imgDir + "splash.png")); } catch (IOException e) { e.printStackTrace(); } final BufferedImage img2 = img; JPanel panel = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(img2, 0, 0, null); } }; panel.setOpaque(true); panel.setLayout(new BorderLayout()); panel.setPreferredSize(new Dimension(800, 600)); panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 300, 0)); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); buttonPanel.setOpaque(false); //Buttons JButton loadMap = new JButton("Load Graph"); loadMap.setActionCommand("loadGraph"); loadMap.addActionListener(new SplashActionHandler()); buttonPanel.add(loadMap); JButton newMap = new JButton("New Graph"); newMap.setActionCommand("newGraph"); newMap.addActionListener(new SplashActionHandler()); buttonPanel.add(newMap); panel.add(buttonPanel, BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:net.fenyo.gnetwatch.GUI.AwtGUI.java
/** * Removes an AWT frame.//w w w . ja va 2s . c o m * @param frame frame to remove. * @return void. */ // GUI thread public void dropFrame(final JFrame frame) { synchronized (frame_list) { frame_list.remove(frame); } frame.dispose(); }
From source file:es.emergya.ui.base.plugins.PluggableJTabbedPane.java
@Override protected void finalize() throws Throwable { for (JFrame f : detached_tabs) f.dispose(); super.finalize(); }
From source file:com.heliosdecompiler.bootstrapper.Bootstrapper.java
private static HeliosData loadHelios() throws IOException { System.out.println("Finding Helios implementation"); HeliosData data = new HeliosData(); boolean needsToDownload = !IMPL_FILE.exists(); if (!needsToDownload) { try (JarFile jarFile = new JarFile(IMPL_FILE)) { ZipEntry entry = jarFile.getEntry("META-INF/MANIFEST.MF"); if (entry == null) { needsToDownload = true;/*from w ww . ja va2 s . c om*/ } else { Manifest manifest = new Manifest(jarFile.getInputStream(entry)); String ver = manifest.getMainAttributes().getValue("Implementation-Version"); try { data.buildNumber = Integer.parseInt(ver); data.version = manifest.getMainAttributes().getValue("Version"); data.mainClass = manifest.getMainAttributes().getValue("Main-Class"); } catch (NumberFormatException e) { needsToDownload = true; } } } catch (IOException e) { needsToDownload = true; } } if (needsToDownload) { URL latestJar = new URL(LATEST_JAR); System.out.println("Downloading latest Helios implementation"); FileOutputStream out = new FileOutputStream(IMPL_FILE); HttpURLConnection connection = (HttpURLConnection) latestJar.openConnection(); if (connection.getResponseCode() == 200) { int contentLength = connection.getContentLength(); if (contentLength > 0) { InputStream stream = connection.getInputStream(); byte[] buffer = new byte[1024]; int amnt; AtomicInteger total = new AtomicInteger(); AtomicBoolean stop = new AtomicBoolean(false); Thread progressBar = new Thread() { public void run() { JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); JLabel label = new JLabel(); label.setText("Downloading latest Helios build"); panel.add(label); GridLayout layout = new GridLayout(); layout.setColumns(1); layout.setRows(3); panel.setLayout(layout); JProgressBar pbar = new JProgressBar(); pbar.setMinimum(0); pbar.setMaximum(100); panel.add(pbar); JTextArea textArea = new JTextArea(1, 3); textArea.setOpaque(false); textArea.setEditable(false); textArea.setText("Downloaded 00.00MB/00.00MB"); panel.add(textArea); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setContentPane(panel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); while (!stop.get()) { SwingUtilities.invokeLater( () -> pbar.setValue((int) (100.0 * total.get() / contentLength))); textArea.setText("Downloaded " + bytesToMeg(total.get()) + "MB/" + bytesToMeg(contentLength) + "MB"); try { Thread.sleep(100); } catch (InterruptedException ignored) { } } frame.dispose(); } }; progressBar.start(); while ((amnt = stream.read(buffer)) != -1) { out.write(buffer, 0, amnt); total.addAndGet(amnt); } stop.set(true); return loadHelios(); } else { throw new IOException("Content-Length set to " + connection.getContentLength()); } } else if (connection.getResponseCode() == 404) { // Most likely bootstrapper is out of date throw new RuntimeException("Bootstrapper out of date!"); } else { throw new IOException(connection.getResponseCode() + ": " + connection.getResponseMessage()); } } return data; }
From source file:net.brtly.monkeyboard.gui.MasterControlPanel.java
private void initWindowListener(final JFrame frame) { frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) { }// w w w .j a v a2 s . com public void windowClosing(WindowEvent e) { frame.dispose(); } public void windowClosed(WindowEvent e) { for (Runnable onClose : _runOnClose) { onClose.run(); } } }); }