Example usage for javax.swing JFrame setLocationRelativeTo

List of usage examples for javax.swing JFrame setLocationRelativeTo

Introduction

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

Prototype

public void setLocationRelativeTo(Component c) 

Source Link

Document

Sets the location of the window relative to the specified component according to the following scenarios.

Usage

From source file:uk.ac.babraham.BamQC.Graphs.ScatterGraph.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override/*from ww  w .  java  2  s.com*/
        public void run() {
            Random r = new Random();
            int sampleSize = 1000;
            double[] data = new double[sampleSize];
            double[] xCategories = new double[sampleSize];
            String[] toolTipsLabels = new String[sampleSize];
            for (int i = 0; i < sampleSize; i++) {
                data[i] = Math.log((r.nextGaussian() * 1.5 + 10) * i + 50);
                xCategories[i] = Math.log(i + 50);
                toolTipsLabels[i] = String.valueOf(i);
            }

            String xLabel = "xLabel";
            String yLabel = "yLabel";
            //String yLabel = null;
            String graphTitle = "Graph Title";

            JFrame frame = new JFrame();
            ScatterGraph scatterGraph = new ScatterGraph(data, xCategories, toolTipsLabels, xLabel, yLabel,
                    graphTitle);

            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(500, 500);
            frame.add(scatterGraph);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
}

From source file:view.WorkspacePanel.java

private void openPdfReaderFromFile(File file) {
    if (testPdf(file)) {
        String filePath = file.getAbsolutePath();
        SwingController sc = new SwingController();
        SwingViewBuilder factory = new SwingViewBuilder(sc);
        JPanel viewerComponentPanel = factory.buildViewerPanel();
        ComponentKeyBinding.install(sc, viewerComponentPanel);
        sc.getDocumentViewController().setAnnotationCallback(
                new org.icepdf.ri.common.MyAnnotationCallback(sc.getDocumentViewController()));
        JFrame window = new JFrame(filePath);
        window.getContentPane().add(viewerComponentPanel);
        window.pack();/*from  w w w  .j av  a2 s. c o  m*/
        window.setLocationRelativeTo(null);
        window.setVisible(true);
        sc.openDocument(filePath);
        file.deleteOnExit();
    } else {
        JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("msg.extractedFileCorrupted"),
                WordUtils.capitalize(Bundle.getBundle().getString("error")), JOptionPane.ERROR_MESSAGE);
        controller.Logger.getLogger().addEntry(Bundle.getBundle().getString("fileCorrupted"));
    }
}