Java Code Examples for javax.swing.JFrame#setLocationByPlatform()

The following examples show how to use javax.swing.JFrame#setLocationByPlatform() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Main.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
public static JFrame launch(Component contents, JMenuBar menuBar) {
   window = new JFrame("Oculus");
   window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   if(menuBar != null) {
      window.setJMenuBar(menuBar);
   }
   window.setLayout(new BorderLayout());
   window.getContentPane().add(createNotificationPanel(), BorderLayout.NORTH);
   window.getContentPane().add(contents, BorderLayout.CENTER);
   window.getContentPane().add(createStatusPanel(), BorderLayout.SOUTH);

   int width = 1400;
   int height = 1000;
   Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
   window.setBounds((int)screen.getWidth()/2 - width/2, (int)screen.getHeight()/2 - height/2, width, height);
   window.setLocationByPlatform(true);

   window.setVisible(true);
   Oculus.setMainWindow(window);
   return window;
}
 
Example 2
Source File: InstallerGUI.java    From EasyMPermission with MIT License 6 votes vote down vote up
/**
 * Creates a new installer that starts out invisible.
 * Call the {@link #show()} method on a freshly created installer to render it.
 */
public InstallerGUI() {
	appWindow = new JFrame(String.format("Project Lombok v%s - Installer", Version.getVersion()));
	
	appWindow.setLocationByPlatform(true);
	appWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	appWindow.setResizable(false);
	appWindow.setIconImage(Toolkit.getDefaultToolkit().getImage(Installer.class.getResource("lombokIcon.png")));
	
	try {
		javacArea = buildJavacArea();
		ideArea = buildIdeArea();
		uninstallArea = buildUninstallArea();
		uninstallArea.setVisible(false);
		howIWorkArea = buildHowIWorkArea();
		howIWorkArea.setVisible(false);
		buildChrome(appWindow.getContentPane());
		appWindow.pack();
	} catch (Throwable t) {
		handleException(t);
	}
}
 
Example 3
Source File: JIntegerTextField.java    From LGoodDatePicker with MIT License 5 votes vote down vote up
private void runDemo() {
    JFrame frame = new JFrame();
    frame.setLayout(new GridBagLayout());
    frame.setSize(300, 300);
    frame.add(this);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}
 
Example 4
Source File: SwiftExplorer.java    From swift-explorer with Apache License 2.0 5 votes vote down vote up
private static void openMainWindow(final MainPanel cp) throws IOException {
    JFrame frame = new JFrame(Configuration.INSTANCE.getAppName());
    
    Dimension screenSize =  java.awt.Toolkit.getDefaultToolkit().getScreenSize() ;
    
    float ratio = (float) 0.8 ;
    Dimension windowSize = new Dimension ((int)(screenSize.getWidth() * ratio), (int)(screenSize.getHeight() * ratio)) ;

    frame.setSize(windowSize.getSize());
    frame.setLocationByPlatform(true);
    frame.setIconImage(ImageIO.read(SwiftExplorer.class.getResource("/icons/logo.png")));
    frame.getContentPane().add(cp);
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            if (cp.onClose()) {
                System.exit(0);
            }
        }
    });
    cp.setOwner(frame);
    frame.setJMenuBar(cp.createMenuBar());
    
    // center the frame
    int x = (int) ((screenSize.getWidth() - frame.getWidth()) / 2);
    int y = (int) ((screenSize.getHeight() - frame.getHeight()) / 2);
    frame.setLocation(x, y);
    
    frame.setVisible(true);
}
 
Example 5
Source File: TestGauge.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("serial")
private static void createAndShowUI() {
       final JFrame frame = new JFrame();
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.setLocationByPlatform(true);

       JPanel panel = new JPanel() {
           @Override 
           public Dimension getPreferredSize() {
               return new Dimension(300, 300);
           }
       };

       int min = -1;
       int max = 5;
       
       final DisplayCircular gauge = new DisplayCircular();
       //final RadialQuarterN gauge = new RadialQuarterN();
       //DigitialRadial gauge = new DigitialRadial();
       
       //final DigitalRadial gauge = new DigitalRadial();
       gauge.setDigitalFont(true);
       gauge.setFrameDesign(FrameDesign.ANTHRACITE);//.GOLD);
       //gauge.setPointerType(PointerType.TYPE5);
      // alt.setTextureColor(Color.yellow);//, Texture_Color BRUSHED_METAL and PUNCHED_SHEET);
       gauge.setUnitString("km");
       gauge.setTitle("Elevation");
       gauge.setMinValue(min);
       gauge.setMaxValue(max);
       //gauge.setTicklabelsVisible(true);
       //gauge.setMaxNoOfMajorTicks(10);
       //gauge.setMaxNoOfMinorTicks(10);
       gauge.setBackgroundColor(BackgroundColor.NOISY_PLASTIC);//.BRUSHED_METAL);
       gauge.setGlowColor(Color.orange);//.yellow);
       gauge.setLcdColor(LcdColor.BEIGE_LCD);//.BLACK_LCD);
       //alt.setLcdInfoString("Elevation");
       //alt.setLcdUnitString("km");
       gauge.setLcdValueAnimated(3.50);
       gauge.setValueAnimated(3.5);
       //gauge.setValue(elevationCache);
       gauge.setLcdDecimals(3);
       
       panel.setLayout(new BorderLayout());
       panel.add(gauge, BorderLayout.CENTER);
       frame.add(panel);

       JPanel buttonsPanel = new JPanel();
       JLabel valueLabel = new JLabel("Value:");

       final JTextField valueField = new JTextField(7);
       valueField.setText("30");
       JButton button = new JButton("Set");
       button.addActionListener(new ActionListener(){
           @Override
           public void actionPerformed(ActionEvent e) {
               try {
                   double value = Double.valueOf(valueField.getText());
                   gauge.setValueAnimated(value);
                   gauge.setBackgroundColor(BackgroundColor.WHITE);
                   gauge.setLcdColor(LcdColor.STANDARD_GREEN_LCD);
                   //gauge.setKnobStyle(KnobStyle.BRASS);
                   //gauge.setColor(ColorDef.BLUE);
                   gauge.setLedColor(LedColor.BLUE);
               } catch(NumberFormatException ex) { 
                   //TODO - handle invalid input 
                   System.err.println("invalid input");
               }
           }
       });

       buttonsPanel.add(valueLabel);
       buttonsPanel.add(valueField);
       buttonsPanel.add(button);

       frame.add(buttonsPanel, BorderLayout.NORTH);

       frame.pack();
       frame.setVisible(true);
   }
 
Example 6
Source File: TestLinear.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("serial")
private static void createAndShowUI() {
       final JFrame frame = new JFrame();
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.setLocationByPlatform(true);

       JPanel panel = new JPanel() {
           @Override 
           public Dimension getPreferredSize() {
               return new Dimension(50, 300);
           }
       };
       
       //JPanel temperaturePanel = new JPanel(new FlowLayout());
       DigitialRadial temperatureL = new DigitialRadial();
	temperatureL.setTitle("Air Temperature");
	temperatureL.setUnitString(Msg.getString("temperature.sign.degreeCelsius"));
	temperatureL.setValueAnimated(20);
	temperatureL.setOrientation(Orientation.VERTICAL);
	temperatureL.init(20, 200);
	//temperatureL.setMajorTickmarkType(new TickmarkType(LINE));
	//temperaturePanel.add(temperatureL);
	//dataPanel.add(temperaturePanel);

       panel.setLayout(new BorderLayout());
       panel.add(temperatureL, BorderLayout.CENTER);
       frame.add(panel);

       JPanel buttonsPanel = new JPanel();
       JLabel valueLabel = new JLabel("Value:");

       final JTextField valueField = new JTextField(7);
       valueField.setText("30");
       JButton button = new JButton("Set");
       button.addActionListener(new ActionListener(){
           @Override
           public void actionPerformed(ActionEvent e) {
               try {
                   double value = Double.valueOf(valueField.getText());
                   temperatureL.setValueAnimated(value);
                   //temperatureL.setBackgroundColor(BackgroundColor.WHITE);
                   //temperatureL.setLcdColor(LcdColor.STANDARD_GREEN_LCD);
                   //temperatureL.setKnobStyle(KnobStyle.BRASS);
                   //temperatureL.setColor(ColorDef.BLUE);
                   temperatureL.setLedColor(LedColor.BLUE);
               } catch(NumberFormatException ex) { 
                   //TODO - handle invalid input 
                   System.err.println("invalid input");
               }
           }
       });

       buttonsPanel.add(valueLabel);
       buttonsPanel.add(valueField);
       buttonsPanel.add(button);

       frame.add(buttonsPanel, BorderLayout.NORTH);

       frame.pack();
       frame.setVisible(true);
   }
 
Example 7
Source File: TestLED.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("serial")
private void createAndShowUI() {
       final JFrame frame = new JFrame();
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.setLocationByPlatform(true);

       JPanel panel = new JPanel() {
           @Override 
           public Dimension getPreferredSize() {
               return new Dimension(100, 100);
           }
       };
       
       //JPanel temperaturePanel = new JPanel(new FlowLayout());
       Led led = new Led();
       //led.setLedBlinking(true); 
	//temperatureL.setTitle("Air Temperature");
	//temperatureL.setUnitString(Msg.getString("temperature.sign.degreeCelsius"));
	//temperatureL.setValueAnimated(20);
	//temperatureL.setOrientation(Orientation.VERTICAL);
	//temperatureL.init(20, 200);
	//temperatureL.setMajorTickmarkType(new TickmarkType(LINE));
	//temperaturePanel.add(temperatureL);
	//dataPanel.add(temperaturePanel);

       panel.setLayout(new BorderLayout());
       panel.add(led, BorderLayout.CENTER);
       frame.add(panel);

       JPanel buttonsPanel = new JPanel();
       //JLabel valueLabel = new JLabel("Value:");

       //final JTextField valueField = new JTextField(7);
       //valueField.setText("30");
       JButton button = new JButton(state);
       button.addActionListener(new ActionListener(){
           @Override
           public void actionPerformed(ActionEvent e) {
               try {
                   //double value = Double.valueOf(valueField.getText());
                   if (toggle_on_off) {
                   	toggle_on_off = false;
                   	state = "Off";
                       led.setLedBlinking(false);
                   }
                   else {
                   	toggle_on_off = true;
                   	state = "On";
                   }
                   led.setLedOn(toggle_on_off);
                   button.setText(state);
                   //led.setBackgroundColor(BackgroundColor.WHITE);
                   //led.setLcdColor(LcdColor.STANDARD_GREEN_LCD);
                   //led.setKnobStyle(KnobStyle.BRASS);
                   //led.setColor(ColorDef.BLUE);
                   //led.setLedColor(LedColor.BLUE);
               } catch(NumberFormatException ex) { 
                   //TODO - handle invalid input 
                   System.err.println("invalid input");
               }
           }
       });

       //buttonsPanel.add(valueLabel);
       //buttonsPanel.add(valueField);
       buttonsPanel.add(button);

       frame.add(buttonsPanel, BorderLayout.NORTH);

       frame.pack();
       frame.setVisible(true);
   }
 
Example 8
Source File: TestLCD.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("serial")
private void createAndShowUI() {
       final JFrame frame = new JFrame();
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.setLocationByPlatform(true);

       JPanel panel = new JPanel() {
           @Override 
           public Dimension getPreferredSize() {
               return new Dimension(200, 100);
           }
       };
       
       //JPanel temperaturePanel = new JPanel(new FlowLayout());
       DisplayRectangular lcd = new DisplayRectangular();
       //led.setLedBlinking(true); 
	//lcd.setTitle("Air Temperature");
	lcd.setLcdInfoString("Latitude");
	//lcd.setLcdText("Latitude");
	lcd.setLcdValueAnimated(20);
       lcd.setBackgroundColor(BackgroundColor.BEIGE);
       
       DisplaySingle lcd1 = new DisplaySingle();
       lcd1.setLcdText("Latitude");
       lcd1.setSectionsVisible(true);
       lcd1.setLcdTextScrolling(true);
       lcd1.setLcdUnitString("N");
       lcd1.setLcdValueAnimated(2.3);
       lcd1.setLcdInfoString("Lat");
       //lcd1.setGlowColor(Color.orange);
       //LcdColor LcdColor = LcdColor.BLUELIGHTBLUE_LCD
	lcd1.setLcdColor(LcdColor.BLUELIGHTBLUE_LCD);
       //lcd.setLcdColor(LcdColor.STANDARD_GREEN_LCD);
	//temperatureL.setOrientation(Orientation.VERTICAL);
	//lcd1.init(100, 50);
	lcd1.setSize(new Dimension(200, 100));
	//temperatureL.setMajorTickmarkType(new TickmarkType(LINE));
	//temperaturePanel.add(temperatureL);
	//dataPanel.add(temperaturePanel);

	
	DisplayMulti dm = new DisplayMulti();
	dm.setLcdUnitString("S");
	dm.setLcdValueAnimated(1.5);
	dm.setLcdColor(LcdColor.BLUELIGHTBLUE_LCD);
	dm.setLcdInfoString("Lat");
	
       panel.setLayout(new BorderLayout());
       panel.add(lcd1, BorderLayout.CENTER);
       frame.add(panel);

       JPanel buttonsPanel = new JPanel();
       //JLabel valueLabel = new JLabel("Value:");

       //final JTextField valueField = new JTextField(7);
       //valueField.setText("30");
       JButton button = new JButton(state);
       button.addActionListener(new ActionListener(){
           @Override
           public void actionPerformed(ActionEvent e) {
               try {
                   //double value = Double.valueOf(valueField.getText());
                   if (toggle_on_off) {
                   	toggle_on_off = false;
                   	state = "Off";
                       
                   }
                   else {
                   	toggle_on_off = true;
                   	state = "On";
                   }
                   //led.setLedOn(toggle_on_off);
                   button.setText(state);
                   //led.setKnobStyle(KnobStyle.BRASS);
                   //led.setColor(ColorDef.BLUE);
                   //led.setLedColor(LedColor.BLUE);
               } catch(NumberFormatException ex) { 
                   //TODO - handle invalid input 
                   System.err.println("invalid input");
               }
           }
       });

       //buttonsPanel.add(valueLabel);
       //buttonsPanel.add(valueField);
       buttonsPanel.add(button);

       frame.add(buttonsPanel, BorderLayout.NORTH);

       frame.pack();
       frame.setVisible(true);
   }
 
Example 9
Source File: Command.java    From jsqsh with Apache License 2.0 4 votes vote down vote up
public JTextAreaCaptureStream(Session session,
        ByteArrayOutputStream buffer) {
    
    super(buffer, true);
    this.buffer = buffer;
    this.session = session;
    
    int width = 600;
    int height = 400;
    
    DimensionVariable v =
        (DimensionVariable) session.getVariableManager()
        .getVariable("window_size");
    
    if (v != null) {
        
        width = v.getWidth();
        height = v.getHeight();
    }
    
    JFrame frame = new JFrame();
    
    // Set the frame characteristics
    frame.setTitle("Query Results");
    frame.setSize(width, height);
    frame.setLocationByPlatform(true);

    // Create a panel to hold all other components
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());
    frame.getContentPane().add(topPanel);
    
    textArea = new JTextArea();
    textArea.setLineWrap(false);
    
    FontVariable fontVar =
        (FontVariable) session.getVariableManager()
            .getVariable("font");
    
    if (fontVar != null) {
        
        textArea.setFont(new Font(fontVar.getFontName(), Font.PLAIN,
            fontVar.getFontSize() ));
    }
    else {
    
        textArea.setFont(new Font( "Monospaced", Font.PLAIN, 10 ));
    }
    
    // Add the table to a scrolling pane
    JScrollPane scrollPane = new JScrollPane(textArea,
        ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    topPanel.add( scrollPane, BorderLayout.CENTER );
    
    frame.setVisible(true);
}