Java Code Examples for javax.swing.JFrame.setLocationRelativeTo()

The following are Jave code examples for showing how to use setLocationRelativeTo() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: SE2017-Team1   File: TestUtil.java   View Source Code Vote up 7 votes
public static void drawAndSave(JPanel graphDrawing, String fileName) {
    JFrame frame = new JFrame("Drawing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(graphDrawing);
    frame.setSize(500, 500);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    exportToImage("jpg", graphDrawing, fileName);
    frame.dispose();
}
 
Example 2
Project: incubator-netbeans   File: KeyboardPopupSwitcherTestHid.java   View Source Code Vote up 6 votes
private JFrame createFrame() {
    JFrame frame = new JFrame(getClass().getName());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(new Dimension(600, 400));
    frame.setLocationRelativeTo(null);
    return frame;
}
 
Example 3
Project: smile_1.5.0_java7   File: PoissonDistributionDemo.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
    JFrame frame = new JFrame("Poisson Distribution");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.getContentPane().add(new PoissonDistributionDemo());
    frame.setVisible(true);
}
 
Example 4
Project: smile_1.5.0_java7   File: D4WaveletDemo.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
    JFrame frame = new JFrame("D4 Wavelet");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.add(new D4WaveletDemo());
    frame.setVisible(true);
}
 
Example 5
Project: Install_Builder_Universal   File: ExtractWindow.java   View Source Code Vote up 6 votes
public ExtractWindow(String zipName, Logger log) {
	this.zipName = zipName;
	this.log = log;

	frame = new JFrame();
	frame.setTitle("Extracting Files");
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setSize(300, 80);
	frame.setLocationRelativeTo(null);
	frame.setResizable(false);
	frame.setLayout(null);
	
	panel = new JPanel();
	frame.add(panel);
	
	init();
}
 
Example 6
Project: human-mobility-modeling-utilities   File: RegularBinningTest.java   View Source Code Vote up 6 votes
public static void main(String[] args) {

		JFrame frame = new JFrame("Displacement plot");
		frame.setSize(new Dimension(800, 300));
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.getContentPane().add(new RegularBinningTest());
        frame.setVisible(true);
	        
	}
 
Example 7
Project: openjdk-jdk10   File: TransparentVImage.java   View Source Code Vote up 6 votes
private static void constructTestUI() {
    testFrame = new JFrame();
    testFrame.setSize(600, 600);
    testFrame.setResizable(false);
    testFrame.getContentPane().add(new TransparentVImage());

    testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    testFrame.setLocationRelativeTo(null);
    testFrame.setVisible(true);
}
 
Example 8
Project: smile_1.5.0_java7   File: HeatmapDemo.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
    try {
        RESParser parser = new RESParser();
        AttributeDataset data = parser.parse("RES", smile.data.parser.IOUtils.getTestDataFile("microarray/all_aml_test.res"));
        
        double[][] x = data.toArray(new double[data.size()][]);
        String[] genes = data.toArray(new String[data.size()]);
        String[] arrays = new String[data.attributes().length];
        for (int i = 0; i < arrays.length; i++) {
            arrays[i] = data.attributes()[i].getName();
        }

        JFrame frame = new JFrame("Heatmap");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.getContentPane().add(Heatmap.plot(genes, arrays, x, Palette.jet(256)));
        frame.setVisible(true);
    } catch (Exception ex) {
        System.err.println(ex);
    }
}
 
Example 9
Project: smile_1.5.0_java7   File: BernoulliDistributionDemo.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
    JFrame frame = new JFrame("Bernoulli Distribution");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.getContentPane().add(new BernoulliDistributionDemo());
    frame.setVisible(true);
}
 
Example 10
Project: zooracle   File: VisualSortDemo.java   View Source Code Vote up 6 votes
public static void main(String[] args)
	{
//		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
//		logger.info(Core.VERSION);
		final ArrayList<File> animalFiles = new ArrayList<File>();
		final JFrame frame = new JFrame();
		frame.setSize(200, 100);
		
		
		frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
		
		final JButton createModelButton = new JButton("create model");
		JButton compareButton = new JButton("compare");
		
		createModelButton.addActionListener(new ActionListener() {
			

			public void actionPerformed(ActionEvent e) {
				dir = FileUtils.selectDirectory(frame, "select folder with (old) .zoo-files to create model");
				ArrayList<File> animalFile = new ArrayList<File>();
				FileUtils.getImages(dir, animalFile, true);
				createModelButton.setText("CREATING!");
				try {
					generateCodeBook(animalFile, new File(osBaseDir + "_.json"));
				} catch (IOException e1) {
					e1.printStackTrace();
				}
				createModelButton.setText("DONE!");
				createModelButton.setEnabled(false);
			}
		});
		
		frame.add(createModelButton);
//		frame.add(compareButton);
		
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			
	}
 
Example 11
Project: Tarski   File: OurDialog.java   View Source Code Vote up 6 votes
/** Display a simple non-modal window showing some text. */
public static JFrame showtext(String title, String text) {
   JFrame window = new JFrame(title);
   JButton done = new JButton("Close");
   done.addActionListener(Runner.createDispose(window));
   JScrollPane scrollPane = OurUtil.scrollpane(OurUtil.textarea(text, 20, 60, false, false));
   window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
   window.getContentPane().setLayout(new BorderLayout());
   window.getContentPane().add(scrollPane, BorderLayout.CENTER);
   window.getContentPane().add(done, BorderLayout.SOUTH);
   window.pack();
   window.setSize(500, 500);
   window.setLocationRelativeTo(null);
   window.setVisible(true);
   return window;
}
 
Example 12
Project: openjdk-jdk10   File: DockIconRepaint.java   View Source Code Vote up 6 votes
private static void createUI() {
    frame = new JFrame();
    frame.setUndecorated(true);
    frame.setSize(300, 300);
    frame.setLocationRelativeTo(null);
    final JDesktopPane pane = new JDesktopPane();
    final JPanel panel = new JPanel() {
        @Override
        protected void paintComponent(Graphics g) {
            g.setColor(color);
            g.fillRect(0, 0, getWidth(), getHeight());
        }
    };
    jif = new JInternalFrame();
    jif.add(panel);
    jif.setVisible(true);
    jif.setSize(300, 300);
    pane.add(jif);
    frame.add(pane);
    frame.setVisible(true);
}
 
Example 13
Project: Install_Builder_Universal   File: InstallBuilderWindow.java   View Source Code Vote up 6 votes
/** Makes The Window */
public InstallBuilderWindow(final String title, final Logger log) {
	
	this.log = log;
	frame = new JFrame();
	frame.setTitle(title);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setSize(WIDTH, HEIGHT);
	frame.setLocationRelativeTo(null);
	frame.setLayout(null);
	frame.setResizable(false);
	
	panel = new JPanel();
	frame.add(panel);
	
	log.Info("Initializing Components...");
	initialize();
	log.Info("Initialized components successfully!");
}
 
Example 14
Project: openjdk-jdk10   File: HiddenDefaultButtonTest.java   View Source Code Vote up 6 votes
private static void createGUI() {
    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton button = new JButton("Default button");
    button.setDefaultCapable(true);
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ButtonClickCount++;
        }
    });

    frame.add(button);
    button.setVisible(false);

    frame.getRootPane().setDefaultButton(button);

    frame.setSize(200, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
 
Example 15
Project: SpeechToText-REST   File: ExtendedExample.java   View Source Code Vote up 5 votes
private static void createAndShowGUI() {
  JFrame frame = new JFrame("Extended Speech Services Example");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(new ExtendedExample());
  frame.pack();
  frame.setVisible(true);
  frame.setLocationRelativeTo(null);
}
 
Example 16
Project: geomapapp   File: MapApp.java   View Source Code Vote up 5 votes
protected void initLayerManager() {

		JFrame d = new JFrame();
		d.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				((JCheckBoxMenuItem)(XML_Menu.commandToMenuItemHash.get("layer_manager_cmd"))).setSelected(false);
			}
		});
		LayerManager lm;
		
		//use existing layer manager if it already exists
		if (layerManager != null) {
			lm = layerManager;
		} else {
			lm = new LayerManager();
		}
		
		lm.setLayerList( toLayerList(map.overlays) );
		lm.setMap(map);

		lm.setDialog(d);
		JScrollPane sp = new JScrollPane(lm);
		sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		d.setTitle("Layer Manager");
		d.setContentPane(sp);
//		d.getContentPane().add(sp);
		d.pack();
		d.setSize(new Dimension(lm.getPreferredSize().width+20,lm.getPreferredSize().height+55));
		d.setMaximumSize(new Dimension(400,300));

		d.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
		d.setLocationRelativeTo(frame);
		d.setState(Frame.NORMAL);
		d.setAlwaysOnTop(true);
		this.layerManager = lm;
		this.layerManagerDialog = d;	
	}
 
Example 17
Project: N-Queen-Puzzle-Knight-sTour   File: Queen.java   View Source Code Vote up 5 votes
public static void main(String[] args){

 dimension = Integer.parseInt(args[0]);
 size = Integer.parseInt(args[1]);
 dim = dimension * size;
 JFrame frame = new JFrame();
 frame.setSize(dim+2* + margin, dim+2* + margin + size / 2);
 frame.getContentPane().add(new Queen());
 frame.setLocationRelativeTo(null);
 frame.setBackground(Color.LIGHT_GRAY);
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 frame.setVisible(true);
 t = new char[dimension][dimension];
     enumerate(dimension);
 }
 
Example 18
Project: jdk8u-jdk   File: MultiGradientTest.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    final JFrame frame = new JFrame("Multistop Gradient Demo");
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            frame.dispose();
        }
    });
    frame.add(new MultiGradientTest());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
 
Example 19
Project: smile_1.5.0_java7   File: ApproximateStringSearchDemo.java   View Source Code Vote up 5 votes
public static void main(String argv[]) {
    ApproximateStringSearchDemo demo = new ApproximateStringSearchDemo();
    JFrame f = new JFrame("Approximate String Search");
    f.setSize(new Dimension(1000, 1000));
    f.setLocationRelativeTo( null );
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(demo);
    f.setVisible(true);
}
 
Example 20
Project: sbc-qsystem   File: Uses.java   View Source Code Vote up 4 votes
public static void setLocation(JFrame component) {
    component.setLocationRelativeTo(null);
    //component.setLocation((Math.round(firstMonitor.getDefaultConfiguration().getBounds().width - component.getWidth()) / 2),
    //        (Math.round(firstMonitor.getDefaultConfiguration().getBounds().height - component.getHeight()) / 2));
}