List of usage examples for javax.swing JFrame setLocationRelativeTo
public void setLocationRelativeTo(Component c)
From source file:components.FrameDemo2.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread.// w ww . jav a 2s .c om */ private static void createAndShowGUI() { //Use the Java look and feel. try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { } //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); //Instantiate the controlling class. JFrame frame = new JFrame("FrameDemo2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. FrameDemo2 demo = new FrameDemo2(); //Add components to it. Container contentPane = frame.getContentPane(); contentPane.add(demo.createOptionControls(), BorderLayout.CENTER); contentPane.add(demo.createButtonPane(), BorderLayout.PAGE_END); frame.getRootPane().setDefaultButton(defaultButton); //Display the window. frame.pack(); frame.setLocationRelativeTo(null); //center it frame.setVisible(true); }
From source file:FrameDemo2.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. */// w w w . j av a 2 s . com private static void createAndShowGUI() { // Use the Java look and feel. try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { } // Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); // Instantiate the controlling class. JFrame frame = new JFrame("FrameDemo2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create and set up the content pane. FrameDemo2 demo = new FrameDemo2(); // Add components to it. Container contentPane = frame.getContentPane(); contentPane.add(demo.createOptionControls(), BorderLayout.CENTER); contentPane.add(demo.createButtonPane(), BorderLayout.PAGE_END); frame.getRootPane().setDefaultButton(defaultButton); // Display the window. frame.pack(); frame.setLocationRelativeTo(null); // center it frame.setVisible(true); }
From source file:InnerClass.java
public InnerClass() { JButton close = new JButton("Close"); ButtonListener listener = new ButtonListener(); close.addActionListener(listener);/* www .j a v a 2 s . c o m*/ JFrame f = new JFrame(); f.add(close); f.setSize(300, 200); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public Main() { Map<Integer, Student> map = createMap(); JComboBox cbox = createComboBox(map); JFrame frame = new JFrame(); frame.add(cbox);//from w ww. j a va2 s.c o m frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:MultipleListeners.java
public MultipleListeners() { JPanel panel = new JPanel(); JButton add = new JButton("+"); add.addActionListener(new ButtonListener1()); add.addActionListener(new ButtonListener2()); panel.add(add);// w ww .j a v a 2s .co m panel.add(spinner); JFrame f = new JFrame(); f.add(panel); f.add(statusbar, BorderLayout.SOUTH); f.setSize(300, 200); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:sim.MarkersChart.java
/** * Display the chart (plot it)/*from w w w .j a va 2 s. c om*/ * * Code from gs-algo ChartMeasure class outputPlot() method, SCREEN case. * This is done so that we can set JFrame to center of display via * setLocationRelativeTo(null). Has been fixed in GS 1.3. */ public void display() { ChartPanel panel = new ChartPanel(chart, params.width, params.height, params.width, params.height, params.width + 50, params.height + 50, true, true, true, true, true, true); JFrame frame = new JFrame(params.title); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLocationRelativeTo(null); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:tarea1.histogram.java
private void display() { JFrame f = new JFrame("Histogram"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(createChartPanel());/* ww w . j ava2 s .c o m*/ f.add(new JLabel(new ImageIcon(image)), BorderLayout.WEST); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:com.github.rosjava.rosjava_catkin_package_a.my_pub_sub_tutorial.CirclesDemo.java
public CirclesDemo() { JFrame frame = new JFrame(); frame.add(panel);/*from w w w. j av a 2s . c o m*/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public Main() { tabbedPane.add(new JScrollPane(createTabbedPanel()), "Tab " + i); add.addActionListener(e -> {//from w w w . j ava2s.c o m i++; tabbedPane.add(new JScrollPane(createTabbedPanel()), "Tab " + i); }); JFrame frame = new JFrame(); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); buttonPanel.add(add); frame.add(buttonPanel, BorderLayout.PAGE_START); frame.add(tabbedPane); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:org.sunzoft.sunstock.StockMain.java
protected void initGUI() { final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(1024, 600);/* www. j a v a 2 s . c o m*/ frame.setLocationRelativeTo(null); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { // Container contentPane = frame.getContentPane(); contentPane.setLayout(new BorderLayout(0, 0)); JFreeChart chart = createChart(); // 6:chartPanel chartPanel = new ChartPanel(chart); chartPanel.setMouseZoomable(true); contentPane.add(chartPanel, BorderLayout.CENTER); JPanel pCtrl = new JPanel(); if (profits.size() > 0) { startInput.setText(profits.get(0).date); endInput.setText(profits.get(profits.size() - 1).date); } else { startInput.setText("20100101"); endInput.setText("20100101"); } pCtrl.add(new JLabel("")); pCtrl.add(startInput); pCtrl.add(new JLabel("")); pCtrl.add(endInput); JButton confirm = new JButton(""); confirm.addActionListener(StockMain.this); pCtrl.add(confirm); contentPane.add(pCtrl, BorderLayout.NORTH); JPanel pStatus = new JPanel(); statusLabel = new JLabel(getStatusText()); pStatus.add(statusLabel); contentPane.add(pStatus, BorderLayout.SOUTH); frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH); frame.setVisible(true); //dataSource.close(); } }); }