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:gov.nih.nci.nbia.StandaloneDMV3.java

JFrame showProgress(String message) {
    JFrame f = new JFrame("Info");
    f = new JFrame("Info");
    f.setUndecorated(true);// ww w .  j  a  v  a  2s .c  om

    JPanel p = new JPanel();
    Border margin = new EmptyBorder(30, 20, 20, 20);
    p.setBorder(new TitledBorder(
            new TitledBorder(margin, "", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)),
            message, TitledBorder.LEADING, TitledBorder.TOP, null, null));
    p.setLayout(new BorderLayout(30, 30));
    JProgressBar progressBar = new JProgressBar();
    progressBar.setIndeterminate(true);
    p.add(progressBar, BorderLayout.CENTER);

    f.getContentPane().add(p);
    f.setSize(360, 80);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    return f;
}

From source file:org.owasp.benchmark.score.report.ScatterInterpretation.java

private JFreeChart display(String title, int height) {
    JFrame f = new JFrame(title);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    XYSeriesCollection dataset = new XYSeriesCollection();
    chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    theme.apply(chart);//from  w w  w  .j  ava 2  s  .  c om

    XYPlot xyplot = chart.getXYPlot();
    initializePlot(xyplot);

    makePointer(xyplot, 7, 93, " Ideal vulnerability detection", TextAnchor.TOP_LEFT, 45);
    makePointer(xyplot, 10, 10, " Tool reports nothing is vulnerable", TextAnchor.TOP_LEFT, 45);
    // makePointer( xyplot, 70, 30, " Worse than random", TextAnchor.TOP_LEFT, 45 );
    makePointer(xyplot, 90, 90, "Tool reports everything is vulnerable ", TextAnchor.TOP_LEFT, 45);
    // makePointer( xyplot, 50, 50, "Tool reports vulnerabilities randomly ", TextAnchor.BOTTOM_RIGHT, 225);
    makePointer(xyplot, 50, 50, "Tool reports vulnerabilities randomly ", TextAnchor.TOP_LEFT, 45);

    makeOval(xyplot, 0, 3, 20, 10, 45);
    makeOval(xyplot, 42, 3, 20, 10, 45);
    makeOval(xyplot, 84, 3, 20, 10, 45);
    makeOval(xyplot, 43, 64, 20, 10, 45);

    ChartPanel cp = new ChartPanel(chart, height, height, 400, 400, 1200, 1200, false, false, false, false,
            false, false);
    f.add(cp);
    f.pack();
    f.setLocationRelativeTo(null);
    // f.setVisible(true);
    return chart;
}

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

/**
 * Displays bar chart on the screen using Swing.
 *    This method creates an application containing a bar 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 .jav a 2 s.  c o m
 * @param width frame width in pixels.
 * 
 *    @param height frame height in pixels.
 * 
 *    @return frame containing the bar chart.;
 * 
 */
public JFrame viewBar(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");

    XYPlot plot = (XYPlot) chart.getPlot();

    //Create the bar
    plot.setDataset(0, dataset.getSeriesCollection());
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
    renderer.setSeriesPaint(0, Color.ORANGE);
    renderer.setSeriesShape(0, new Line2D.Double(0, 0, 0, 1000));
    plot.setRenderer(0, renderer);

    //Create the points
    plot.setDataset(1, dataset.getSeriesCollection());
    final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(false, true);
    renderer2.setSeriesPaint(0, Color.ORANGE);
    renderer2.setSeriesShape(0, new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0));
    plot.setRenderer(1, renderer2);

    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.ScatterChart.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.
 * //www  . j  av  a 2 s .  c om
 * @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("ScatterChart from SSJ: " + chart.getTitle().getText());
    else
        myFrame = new JFrame("ScatterChart from SSJ");
    XYPlot plot = chart.getXYPlot();

    /*    // The drawn points are somewhat big, of different shapes, unfilled
          XYLineAndShapeRenderer shape = new XYLineAndShapeRenderer(false, true);
          int nb = getSeriesCollection().getSeriesCollection().getSeriesCount();
          for (int i = 0 ; i < nb ; i++) {
             shape.setSeriesShapesFilled(i, false);
             plot.setRenderer(i, shape);
          }
    */
    // The drawn points are all square, filled
    XYDotRenderer shape = new XYDotRenderer();
    final int dotSize = 3;
    shape.setDotWidth(dotSize);
    shape.setDotHeight(dotSize);
    int nb = getSeriesCollection().getSeriesCollection().getSeriesCount();
    for (int i = 0; i < nb; i++)
        plot.setRenderer(i, shape);

    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:org.owasp.benchmark.score.report.ScatterTools.java

private JFreeChart display(String title, int height, OverallResults or) {

    JFrame f = new JFrame(title);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series = new XYSeries("Scores");
    int totalTools = 0;
    double totalToolTPR = 0;
    double totalToolFPR = 0;
    for (OverallResult r : or.getResults()) {
        series.add(r.falsePositiveRate * 100, r.truePositiveRate * 100);
        totalTools++;//from   w ww  . ja  v  a 2  s.c om
        totalToolTPR += r.truePositiveRate;
        totalToolFPR += r.falsePositiveRate;
    }
    atpr = totalToolTPR / totalTools;
    afpr = totalToolFPR / totalTools;

    if (or.getResults().size() > 1) {
        series.add(afpr * 100, atpr * 100);
    }

    dataset.addSeries(series);

    chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    theme.apply(chart);

    XYPlot xyplot = chart.getXYPlot();

    initializePlot(xyplot);

    makeDataLabels(or, xyplot);
    makeLegend(or, 103, 93, dataset, xyplot);

    XYTextAnnotation time = new XYTextAnnotation("Tool run time: " + or.getTime(), 12, -5.6);
    time.setTextAnchor(TextAnchor.TOP_LEFT);
    time.setFont(theme.getRegularFont());
    time.setPaint(Color.red);
    xyplot.addAnnotation(time);

    ChartPanel cp = new ChartPanel(chart, height, height, 400, 400, 1200, 1200, false, false, false, false,
            false, false);
    f.add(cp);
    f.pack();
    f.setLocationRelativeTo(null);
    // f.setVisible(true);
    return chart;
}

From source file:Assignment2.FarmManagementGUI.java

private void btnPressureChartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPressureChartActionPerformed
    XYSeries signal = new XYSeries("amount");
    XYSeriesCollection dataset = new XYSeriesCollection(signal);

    JFrame f = new JFrame(selectedPlot.getName() + " pressure sensor chart");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    JFreeChart chart = ChartFactory.createXYLineChart(selectedPlot.getName(), "Reading number", "Reading",
            dataset);//from   www  .j a v  a 2 s  . c o m
    f.add(new ChartPanel(chart));
    JPanel p = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    signal.clear();
    Sensor sensor;
    SensorData sensorData;
    for (int i = 0; i < selectedPlot.getSensors().size(); i++) {
        sensor = selectedPlot.getSensors().get(i);
        if (sensor.getSensorType() == SensorType.PRESSURE) {
            for (int j = 0; j < sensor.getSensorDataList().size(); j++) {
                sensorData = sensor.getSensorDataList().get(j);
                signal.add(j, sensorData.getDataRepresentationType());
            }
        }
    }

    f.add(p, BorderLayout.SOUTH);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Assignment2.FarmManagementGUI.java

private void btnLightChartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLightChartActionPerformed
    XYSeries signal = new XYSeries("amount");
    XYSeriesCollection dataset = new XYSeriesCollection(signal);

    JFrame f = new JFrame(selectedPlot.getName() + " light sensor chart");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    JFreeChart chart = ChartFactory.createXYLineChart(selectedPlot.getName(), "Reading number", "Reading",
            dataset);//from w w w .j a  v a2s.c om
    f.add(new ChartPanel(chart));
    JPanel p = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    signal.clear();
    Sensor sensor;
    SensorData sensorData;
    for (int i = 0; i < selectedPlot.getSensors().size(); i++) {
        sensor = selectedPlot.getSensors().get(i);
        if (sensor.getSensorType() == SensorType.LIGHT_SENSOR) {
            for (int j = 0; j < sensor.getSensorDataList().size(); j++) {
                sensorData = sensor.getSensorDataList().get(j);
                signal.add(j, sensorData.getDataRepresentationType());
            }
        }
    }

    f.add(p, BorderLayout.SOUTH);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Assignment2.FarmManagementGUI.java

private void btnAcidityChartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAcidityChartActionPerformed
    XYSeries signal = new XYSeries("amount");
    XYSeriesCollection dataset = new XYSeriesCollection(signal);

    JFrame f = new JFrame(selectedPlot.getName() + " soil acidity sensor chart");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    JFreeChart chart = ChartFactory.createXYLineChart(selectedPlot.getName(), "Reading number", "Reading",
            dataset);/*  w w w  .j ava  2 s  .  c om*/
    f.add(new ChartPanel(chart));
    JPanel p = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    signal.clear();
    Sensor sensor;
    SensorData sensorData;
    for (int i = 0; i < selectedPlot.getSensors().size(); i++) {
        sensor = selectedPlot.getSensors().get(i);
        if (sensor.getSensorType() == SensorType.ACIDITY) {
            for (int j = 0; j < sensor.getSensorDataList().size(); j++) {
                sensorData = sensor.getSensorDataList().get(j);
                signal.add(j, sensorData.getDataRepresentationType());
            }
        }
    }

    f.add(p, BorderLayout.SOUTH);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Assignment2.FarmManagementGUI.java

private void btnSoilMoistureChartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSoilMoistureChartActionPerformed
    XYSeries signal = new XYSeries("amount");
    XYSeriesCollection dataset = new XYSeriesCollection(signal);

    JFrame f = new JFrame(selectedPlot.getName() + " soil moisture sensor chart");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    JFreeChart chart = ChartFactory.createXYLineChart(selectedPlot.getName(), "Reading number", "Reading",
            dataset);/*  w  ww. ja  v a2 s.  c  o m*/
    f.add(new ChartPanel(chart));
    JPanel p = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    signal.clear();
    Sensor sensor;
    SensorData sensorData;
    for (int i = 0; i < selectedPlot.getSensors().size(); i++) {
        sensor = selectedPlot.getSensors().get(i);
        if (sensor.getSensorType() == SensorType.SOIL_MOISTURE) {
            for (int j = 0; j < sensor.getSensorDataList().size(); j++) {
                sensorData = sensor.getSensorDataList().get(j);
                signal.add(j, sensorData.getDataRepresentationType());
            }
        }
    }

    f.add(p, BorderLayout.SOUTH);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Assignment2.FarmManagementGUI.java

private void btnSoilTempChartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSoilTempChartActionPerformed
    XYSeries signal = new XYSeries("amount");
    XYSeriesCollection dataset = new XYSeriesCollection(signal);

    JFrame f = new JFrame(selectedPlot.getName() + " soil temperature sensor chart");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    JFreeChart chart = ChartFactory.createXYLineChart(selectedPlot.getName(), "Reading number", "Reading",
            dataset);//from w ww  . j  a  v a2 s. c om
    f.add(new ChartPanel(chart));
    JPanel p = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    signal.clear();
    Sensor sensor;
    SensorData sensorData;
    for (int i = 0; i < selectedPlot.getSensors().size(); i++) {
        sensor = selectedPlot.getSensors().get(i);
        if (sensor.getSensorType() == SensorType.SOIL_TEMPERATURE) {
            for (int j = 0; j < sensor.getSensorDataList().size(); j++) {
                sensorData = sensor.getSensorDataList().get(j);
                signal.add(j, sensorData.getDataRepresentationType());
            }
        }
    }

    f.add(p, BorderLayout.SOUTH);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}