Example usage for javax.swing JFrame dispose

List of usage examples for javax.swing JFrame dispose

Introduction

In this page you can find the example usage for javax.swing JFrame dispose.

Prototype

public void dispose() 

Source Link

Document

Releases all of the native screen resources used by this Window , its subcomponents, and all of its owned children.

Usage

From source file:pl.otros.logview.gui.markers.editor.NewMarkerAction.java

@Override
public void actionPerformed(ActionEvent e) {
    final JFrame f = new JFrame("Create new marker");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    Container contentPane = f.getContentPane();
    final MarkerEditor editor = new MarkerEditor();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(editor);/*from   w w w  .j  a va2 s. c  om*/

    JButton save = new JButton("Save");
    save.addActionListener(new ActionListener() {

        private final PluginableElementsContainer<AutomaticMarker> markersContainser = AllPluginables
                .getInstance().getMarkersContainser();

        @Override
        public void actionPerformed(ActionEvent arg0) {

            int showSaveDialog = chooser.showSaveDialog((Component) arg0.getSource());
            if (showSaveDialog != JFileChooser.APPROVE_OPTION) {
                return;
            }
            File saveFile = chooser.getSelectedFile();
            Properties markerPropertiesFromView = editor.getMarkerPropertiesFromView();

            try {
                saveMarker(saveFile, markerPropertiesFromView);
            } catch (IOException e) {
                JOptionPane.showMessageDialog(f, "Error saving marker: " + e.getMessage(), "Error",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }
            try {
                AutomaticMarker marker = AutomaticMarkerLoader
                        .loadPropertyBasedMarker(markerPropertiesFromView);
                markersContainser.addElement(marker);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(f, "Error creating marker: " + e.getMessage(), "Error",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }
            f.dispose();
        }
    });
    contentPane.add(save, BorderLayout.SOUTH);

    f.pack();

    f.setVisible(true);
}

From source file:pl.otros.vfs.browser.demo.TestBrowser.java

public static void main(final String[] args)
        throws InterruptedException, InvocationTargetException, SecurityException, IOException {
    if (args.length > 1)
        throw new IllegalArgumentException(
                "SYNTAX:  java... " + TestBrowser.class.getName() + " [initialPath]");

    SwingUtilities.invokeAndWait(new Runnable() {

        @Override/*  w  w  w.j  ava 2s.c o  m*/
        public void run() {
            tryLoadSubstanceLookAndFeel();
            final JFrame f = new JFrame("OtrosVfsBrowser demo");
            Container contentPane = f.getContentPane();
            contentPane.setLayout(new BorderLayout());
            DataConfiguration dc = null;
            final PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
            File favoritesFile = new File("favorites.properties");
            propertiesConfiguration.setFile(favoritesFile);
            if (favoritesFile.exists()) {
                try {
                    propertiesConfiguration.load();
                } catch (ConfigurationException e) {
                    e.printStackTrace();
                }
            }
            dc = new DataConfiguration(propertiesConfiguration);
            propertiesConfiguration.setAutoSave(true);
            final VfsBrowser comp = new VfsBrowser(dc, (args.length > 0) ? args[0] : null);
            comp.setSelectionMode(SelectionMode.FILES_ONLY);
            comp.setMultiSelectionEnabled(true);
            comp.setApproveAction(new AbstractAction(Messages.getMessage("demo.showContentButton")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    FileObject[] selectedFiles = comp.getSelectedFiles();
                    System.out.println("Selected files count=" + selectedFiles.length);
                    for (FileObject selectedFile : selectedFiles) {
                        try {
                            FileSize fileSize = new FileSize(selectedFile.getContent().getSize());
                            System.out.println(selectedFile.getName().getURI() + ": " + fileSize.toString());
                            byte[] bytes = readBytes(selectedFile.getContent().getInputStream(), 150 * 1024l);
                            JScrollPane sp = new JScrollPane(new JTextArea(new String(bytes)));
                            JDialog d = new JDialog(f);
                            d.setTitle("Content of file: " + selectedFile.getName().getFriendlyURI());
                            d.getContentPane().add(sp);
                            d.setSize(600, 400);
                            d.setVisible(true);
                        } catch (Exception e1) {
                            LOGGER.error("Failed to read file", e1);
                            JOptionPane.showMessageDialog(f,
                                    (e1.getMessage() == null) ? e1.toString() : e1.getMessage(), "Error",
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
            });

            comp.setCancelAction(new AbstractAction(Messages.getMessage("general.cancelButtonText")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    f.dispose();
                    try {
                        propertiesConfiguration.save();
                    } catch (ConfigurationException e1) {
                        e1.printStackTrace();
                    }
                    System.exit(0);
                }
            });
            contentPane.add(comp);

            f.pack();
            f.setVisible(true);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        }
    });
}

From source file:Provider.GoogleMapsStatic.TestUI.SampleApp.java

private void _displayImgInFrame() {

    final JFrame frame = new JFrame("Google Static Map");
    GUIUtils.setAppIcon(frame, "71.png");
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    JLabel imgLbl = new JLabel(new ImageIcon(_img));
    imgLbl.setToolTipText(MessageFormat.format("<html>Image downloaded from URI<br>size: w={0}, h={1}</html>",
            _img.getWidth(), _img.getHeight()));
    imgLbl.addMouseListener(new MouseListener() {
        public void mouseClicked(MouseEvent e) {
        }//  w  w w .  j av a 2s  . com

        public void mousePressed(MouseEvent e) {
            frame.dispose();
        }

        public void mouseReleased(MouseEvent e) {
        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }
    });

    frame.setContentPane(imgLbl);
    frame.pack();

    GUIUtils.centerOnScreen(frame);
    frame.setVisible(true);
}

From source file:Provider.GoogleMapsStatic.TestUI.SampleApp.java

private void _displayRespStrInFrame() {

    final JFrame frame = new JFrame("Google Static Map - Error");
    GUIUtils.setAppIcon(frame, "69.png");
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    JTextArea response = new JTextArea(_respStr, 25, 80);
    response.addMouseListener(new MouseListener() {
        public void mouseClicked(MouseEvent e) {
        }/*from w w  w.  ja v  a 2 s .  co  m*/

        public void mousePressed(MouseEvent e) {
            frame.dispose();
        }

        public void mouseReleased(MouseEvent e) {
        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }
    });

    frame.setContentPane(new JScrollPane(response));
    frame.pack();

    GUIUtils.centerOnScreen(frame);
    frame.setVisible(true);
}

From source file:statechum.analysis.learning.Visualiser.java

/** Creates key bindings used in all Statechum windows.
  * //from  www  .java  2 s .  co  m
  * @param frame frame of the window
  * @param windowID the identifier of the window in the config file - used to store/restore window positions
  * @param keyToActionMap map to store key bindings in.
  */
public static void setStateChumKeyBindings(final JFrame frame, final int windowID,
        Map<Integer, Action> keyToActionMap) {
    keyToActionMap.put(KeyEvent.VK_F4,
            new graphAction("saveWindows", "save the current position/size of graph windows") {

                /** Serial number. */
                private static final long serialVersionUID = 4L;

                @Override
                public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
                    globalConfig.saveFrame(frame, windowID);
                    globalConfig.saveConfiguration();
                }
            });

    if (Boolean.valueOf(GlobalConfiguration.getConfiguration()
            .getProperty(GlobalConfiguration.G_PROPERTIES.ESC_TERMINATE))) {
        keyToActionMap.put(KeyEvent.VK_ESCAPE, new graphAction("terminate", "terminates this program") {

            /** Serial number. */
            private static final long serialVersionUID = 5L;

            @Override
            public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
                frame.setVisible(false);
                frame.dispose();
                Visualiser.syncValue.set(true);
                DrawGraphs.end();
                System.exit(1);
                /*
                synchronized (Visualiser.syncObject) {
                Visualiser.syncObject.notify();
                }*/
            }
        });
    }
    keyToActionMap.put(KeyEvent.VK_SPACE, new graphAction("step", "exits the Visualiser.waitForKey() call") {

        /** Serial number. */
        private static final long serialVersionUID = 6L;

        @Override
        public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
            Visualiser.syncValue.set(false);
            synchronized (Visualiser.syncObject) {
                Visualiser.syncObject.notify();
            }
        }
    });

}

From source file:test.uk.co.modularaudio.rackgeneration.GenerateReleaseComponentImages.java

private void generateImageForDefinition(final MadDefinition<?, ?> def)
        throws DatastoreException, RecordNotFoundException, MadProcessingException, IOException {
    final Map<MadParameterDefinition, String> emptyParams = new HashMap<MadParameterDefinition, String>();
    final MadInstance<?, ?> aui = componentService.createInstanceFromDefinition(def, emptyParams,
            def.getName());//from www. ja  v a2 s.c o  m

    final IMadUiInstance<?, ?> auui = componentUiService.createUiInstanceForMad(aui);

    final RackComponent rackComponent = new RackComponent(def.getName(), aui, auui);
    final AbstractGuiAudioComponent frontComponent = guiComponentFactoryService
            .createFrontGuiComponent(rackComponent);

    final JFrame testFrame = new JFrame();
    final JPanel testPanel = new JPanel();
    final MigLayout layout = new MigLayout("insets 0, gap 0, fill");
    testPanel.setLayout(layout);
    testPanel.setOpaque(false);

    final Span cellSpan = auui.getCellSpan();
    final Dimension gridSize = GuiRackPanel.FRONT_GRID_SIZE;
    final int width = cellSpan.x * gridSize.width;
    final int height = cellSpan.y * gridSize.height;
    final Dimension componentSize = new Dimension(width, height);

    final BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g2d = bi.createGraphics();

    frontComponent.setBounds(new Rectangle(0, 0, width, height));
    frontComponent.setSize(componentSize);
    frontComponent.setMinimumSize(componentSize);

    testPanel.add(frontComponent);
    testFrame.add(testPanel);

    testPanel.validate();
    testFrame.pack();

    testFrame.setVisible(true);
    try {
        Thread.sleep(100);
    } catch (final InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    testPanel.paint(g2d);
    testFrame.setVisible(false);
    testFrame.dispose();

    final File defOutputFile = new File("tmpoutput/" + def.getId() + ".png");
    ImageIO.write(bi, "png", defOutputFile);

    componentUiService.destroyUiInstance(auui);
    componentService.destroyInstance(aui);
}

From source file:uk.chromis.pos.forms.JRootApp.java

private void poweredbyMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_poweredbyMouseClicked

    JFrame sampleFrame = new JFrame();
    final Action exit = new AbstractAction("Exit") {
        @Override/*  ww w.  j a  v  a 2s  .co  m*/
        public final void actionPerformed(final ActionEvent e) {
            sampleFrame.setVisible(false);
            sampleFrame.dispose();
        }
    };

    String currentPath = null;

    if (OSValidator.isMac()) {
        try {
            currentPath = new File(
                    JRootApp.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath())
                            .toString();
        } catch (URISyntaxException ex) {
        }
    } else {
        currentPath = System.getProperty("user.dir") + "\\chromispos.jar";
    }

    String md5 = null;
    try {
        FileInputStream fis = new FileInputStream(new File(currentPath));
        md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis);
        fis.close();

    } catch (FileNotFoundException ex) {
        Logger.getLogger(JRootApp.class.getName()).log(Level.SEVERE, null, ex);

    } catch (IOException ex) {
        Logger.getLogger(JRootApp.class.getName()).log(Level.SEVERE, null, ex);
    }

    /*
    int mb = 1024*1024;         
    //Getting the runtime reference from system
    Runtime runtime = Runtime.getRuntime();         
    System.out.println("##### Heap utilization statistics [MB] #####");         
    //Print used memory
    System.out.println("Used Memory:"
    + (runtime.totalMemory() - runtime.freeMemory()) / mb); 
    //Print free memory
    System.out.println("Free Memory:"
    + runtime.freeMemory() / mb);         
    //Print total available memory
    System.out.println("Total Memory:" + runtime.totalMemory() / mb); 
    //Print Maximum available memory
    System.out.println("Max Memory:" + runtime.maxMemory() / mb);
     */
    AboutDialog dialog = new AboutDialog();
    JPanel dialogPanel = new JPanel();
    MigLayout layout = new MigLayout("", "[fill]");
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
    model.addColumn("Details");
    model.addColumn("Value");
    model.addRow(new Object[] { "Database Version", readDataBaseVersion() });
    model.addRow(new Object[] { "Java Version", System.getProperty("java.version") });
    model.addRow(new Object[] { "Jar MD5", md5 });
    model.addRow(new Object[] { "Operating System", System.getProperty("os.name") });
    model.addRow(new Object[] { "Sync library", Sync.getVersion() });

    JScrollPane scrollPane = new JScrollPane(table);
    JPanel mainPanel = new JPanel(layout);
    JLabel label = new JLabel();
    JPanel btnPanel = new JPanel();
    dialogPanel.add(dialog);
    mainPanel.add(dialogPanel, "wrap");
    mainPanel.add(scrollPane, "wrap");
    JButton btnExit = new JButton(exit);
    btnPanel.add(btnExit, "width 100!");
    mainPanel.add(btnPanel, "right, wrap");
    mainPanel.add(new JLabel(), "wrap");
    sampleFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    sampleFrame.setPreferredSize(new Dimension(500, 300));
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    sampleFrame.setLocation(dim.width / 2 - 250, dim.height / 2 - 150);
    sampleFrame.setUndecorated(true);
    mainPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 4));
    sampleFrame.add(mainPanel);
    sampleFrame.pack();
    sampleFrame.setVisible(true);

}

From source file:weka.gui.beans.KnowledgeFlowRemoteSchedulerPerspective.java

/**
 * Main method for testing this class//from w  w w  . j  a va 2  s.  c o m
 * 
 * @param args command line arguments
 */
public static void main(String[] args) {
    final javax.swing.JFrame jf = new javax.swing.JFrame();
    jf.getContentPane().setLayout(new java.awt.BorderLayout());
    KnowledgeFlowRemoteSchedulerPerspective p = new KnowledgeFlowRemoteSchedulerPerspective();

    jf.getContentPane().add(p, BorderLayout.CENTER);
    jf.addWindowListener(new java.awt.event.WindowAdapter() {
        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            jf.dispose();
            System.exit(0);
        }
    });
    jf.setSize(800, 600);
    jf.setVisible(true);
}