Example usage for javax.swing JDialog setLocationByPlatform

List of usage examples for javax.swing JDialog setLocationByPlatform

Introduction

In this page you can find the example usage for javax.swing JDialog setLocationByPlatform.

Prototype

public void setLocationByPlatform(boolean locationByPlatform) 

Source Link

Document

Sets whether this Window should appear at the default location for the native windowing system or at the current location (returned by getLocation ) the next time the Window is made visible.

Usage

From source file:org.drugis.addis.gui.WelcomeDialog.java

private void showExampleInfo(String helpText) {
    final JDialog dialog = new JDialog(this);
    dialog.setLocationByPlatform(true);
    dialog.setPreferredSize(new Dimension(500, 250));

    JComponent helpPane = TextComponentFactory.createTextPane(helpText, true);

    JButton closeButton = new JButton("Close");
    closeButton.setMnemonic('c');
    closeButton.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent arg0) {
            dialog.dispose();//from   w w  w  . j a v a2  s .  c o m
        }
    });

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(helpPane, BorderLayout.CENTER);
    panel.add(closeButton, BorderLayout.SOUTH);

    dialog.add(panel);
    dialog.pack();
    dialog.setVisible(true);
}

From source file:org.languagetool.gui.Tools.java

/**
 * Set dialog location to the center of the screen
 *
 * @param dialog the dialog which will be centered
 * @since 2.6//from  w w w  .  j  ava2s  . c  o  m
 */
public static void centerDialog(JDialog dialog) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = dialog.getSize();
    dialog.setLocation(screenSize.width / 2 - frameSize.width / 2,
            screenSize.height / 2 - frameSize.height / 2);
    dialog.setLocationByPlatform(true);
}