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:freemrs.ChartPanelDraw.java

public ChartPanelDraw(java.util.List<Vitals> result, String type) {
    this.type = type;
    this.result = result;
    dataset = createTimeDataset();/*w  w w  .  jav  a 2  s . co m*/
    chartPanel = createChart(dataset, type);

    JFrame f = new JFrame("Vital Plot"); //Jframe to draw the graph
    f.setTitle("Vital Plot");
    f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    f.setLayout(new BorderLayout(0, 5));
    f.add(chartPanel, BorderLayout.CENTER);
    f.setIconImage(new ImageIcon(getClass().getResource("/images/icon_transparent.png")).getImage());

    chartPanel.setHorizontalAxisTrace(true); //set properties of the graph 
    chartPanel.setVerticalAxisTrace(true);
    chartPanel.setMouseWheelEnabled(true);

    JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel.add(createTrace()); //Add components to panel
    panel.add(createDate());
    panel.add(createZoom());
    f.add(panel, BorderLayout.SOUTH);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:TapTapTap.java

public void createUI() {
    JFrame f = new JFrame("TapTapTap");

    final WaitLayerUI layerUI = new WaitLayerUI();
    JPanel panel = createPanel();
    JLayer<JPanel> jlayer = new JLayer<JPanel>(panel, layerUI);

    final Timer stopper = new Timer(4000, new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            layerUI.stop();//w w w .j av a  2s  . c  om
        }
    });
    stopper.setRepeats(false);

    mOrderButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            layerUI.start();
            if (!stopper.isRunning()) {
                stopper.start();
            }
        }
    });

    f.add(jlayer);

    f.setSize(300, 200);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:EHRAppointment.ChartPanelDraw.java

/**
 *
 * @param result/*from w w w  .  j  av a 2 s .  co m*/
 * @param type
 */
public ChartPanelDraw(java.util.List<Vitals> result, String type) {
    this.type = type;
    this.result = result;
    dataset = createTimeDataset();
    chartPanel = createChart(dataset, type);

    JFrame f = new JFrame("Vital Plot"); //Jframe to draw the graph
    f.setTitle("Vital Plot");
    f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    f.setLayout(new BorderLayout(0, 5));
    f.add(chartPanel, BorderLayout.CENTER);
    f.setIconImage(new ImageIcon(getClass().getResource("/images/icon_transparent.png")).getImage());

    chartPanel.setHorizontalAxisTrace(true); //set properties of the graph 
    chartPanel.setVerticalAxisTrace(true);
    chartPanel.setMouseWheelEnabled(true);

    JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel.add(createTrace()); //Add components to panel
    panel.add(createDate());
    panel.add(createZoom());
    f.add(panel, BorderLayout.SOUTH);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:org.leo.benchmark.Benchmark.java

/**
 * Display benchmark results//from  w  ww.ja va2  s  .  c  om
 */
@SuppressWarnings("serial")
public void displayBenchmarkResults() {
    List<ChartPanel> chartPanels = new ArrayList<ChartPanel>();
    // sort task by names
    List<String> taskNames = new ArrayList<String>(benchResults.keySet());
    Collections.sort(taskNames);
    // browse task name, 1 chart per task
    for (String taskName : taskNames) {
        // time by class
        Map<Class<? extends Collection<?>>, Long> clazzResult = benchResults.get(taskName);

        ChartPanel chartPanel = createChart(taskName, "Time (ns)", clazzResult,
                new StandardCategoryItemLabelGenerator() {
                    @Override
                    public String generateLabel(CategoryDataset dataset, int row, int column) {
                        String label = " " + dataset.getRowKey(row).toString();
                        if (dataset.getValue(row, column).equals(timeout * 1000000)) {
                            label += " (Timeout)";
                        }
                        return label;
                    }
                });

        chartPanels.add(chartPanel);
    }
    // display in a JFrame
    JPanel mainPanel = new JPanel(new GridLayout(chartPanels.size() / 5, 5, 5, 5));
    for (ChartPanel chart : chartPanels) {
        mainPanel.add(chart);
    }
    JFrame frame = new JFrame("Collection Implementations Benchmark");
    frame.getContentPane().add(new JLabel("Collection Implementations Benchmark. Populate size : "
            + populateSize + ", timeout : " + timeout + "ms"), BorderLayout.NORTH);
    frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
    frame.setSize(900, 500);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:umontreal.iro.lecuyer.charts.MultipleDatasetChart.java

/**
 * Displays chart on the screen using Swing.
 *    This method creates an application containing a chart panel displaying
 *    the chart. The created frame is positioned on-screen, and displayed before
 *    it is returned. The <TT>width</TT> and the <TT>height</TT>
 *    of the chart are measured in pixels.
 * //from   www  . j a v  a 2 s.  c om
 * @param width frame width in pixels.
 * 
 *    @param height frame height in pixels.
 * 
 * 
 */
public JFrame view(int width, int height) {
    JFrame myFrame;
    if (chart.getTitle() != null)
        myFrame = new JFrame("MultipleDatasetChart from SSJ: " + chart.getTitle().getText());
    else
        myFrame = new JFrame("MultipleDatasetChart from SSJ");
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
    myFrame.setContentPane(chartPanel);
    myFrame.pack();
    myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    myFrame.setLocationRelativeTo(null);
    myFrame.setVisible(true);
    return myFrame;
}

From source file:umontreal.iro.lecuyer.charts.XYLineChart.java

/**
 * Displays chart on the screen using Swing.
 *    This method creates an application containing a chart panel displaying
 *    the chart. The created frame is positioned on-screen, and displayed before
 *    it is returned. The <TT>width</TT> and the <TT>height</TT>
 *    of the chart are measured in pixels.
 * //from w w w .ja  v  a  2  s .c  o m
 * @param width frame width in pixels.
 * 
 *    @param height frame height in pixels.
 * 
 *    @return frame containing the chart.;
 * 
 */
public JFrame view(int width, int height) {
    JFrame myFrame;
    if (chart.getTitle() != null)
        myFrame = new JFrame("XYLineChart from SSJ: " + chart.getTitle().getText());
    else
        myFrame = new JFrame("XYLineChart from SSJ");
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
    myFrame.setContentPane(chartPanel);
    myFrame.pack();
    myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    myFrame.setLocationRelativeTo(null);
    myFrame.setVisible(true);
    return myFrame;
}

From source file:com.zigabyte.stock.stratplot.StrategyPlotter.java

protected void viewData() {
    if (this.histories == null)
        return;/*ww w . j  a  v  a  2 s  .co m*/
    try {
        JFrame viewer = new StockMarketHistoryViewer(this.loadedHistoriesFile.getPath(), this.histories);
        viewer.setSize(1024, 768);
        viewer.setLocationRelativeTo(this);
        viewer.setVisible(true);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:gov.nih.nci.nbia.StandaloneDMV3.java

JFrame showProgressForMac(String message) {
    JFrame f = new JFrame("Info");
    f.setUndecorated(true);/*ww  w.  ja va 2 s  .c om*/

    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    JLabel waitInfo = new JLabel("Loading your data...");
    waitInfo.setForeground(new Color(105, 105, 105));
    waitInfo.setFont(new Font("Tahoma", Font.BOLD, 13));
    waitInfo.setHorizontalAlignment(JLabel.CENTER);
    waitInfo.setVerticalAlignment(JLabel.CENTER);
    p.add(waitInfo, BorderLayout.CENTER);
    f.getContentPane().add(p);
    f.setSize(360, 40);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    return f;
}

From source file:configuration.Util.java

public static JFrame createSearchFrame() {
    JFrame f = new JFrame();
    f.pack();// w w  w  . j av  a2s .  co  m
    f.setSize(new Dimension(1, 1));
    f.setLocationRelativeTo(null);
    f.setVisible(false);
    f.setAlwaysOnTop(true);
    return f;
}

From source file:org.moeaframework.analysis.plot.Plot.java

/**
 * Displays the chart in a standalone window.
 * //from   w w  w  . j a  va 2  s  .  c o m
 * @param width the width of the chart
 * @param height the height of the chart
 * @return the window that was created
 */
public JFrame show(int width, int height) {
    JFrame frame = new JFrame();

    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(getChartPanel(), BorderLayout.CENTER);

    frame.setPreferredSize(new Dimension(width, height));
    frame.pack();

    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setTitle("MOEA Framework Plot");
    frame.setVisible(true);

    return frame;
}