Example usage for javax.swing JDialog setLocation

List of usage examples for javax.swing JDialog setLocation

Introduction

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

Prototype

@Override
public void setLocation(Point p) 

Source Link

Document

The method changes the geometry-related data.

Usage

From source file:Main.java

public static void setCenterOfParent(JFrame parent, JDialog dialog) {
    Point parentPosition = parent.getLocation();
    Dimension parentSize = parent.getSize();
    Dimension size = dialog.getSize();
    Point position = new Point(parentPosition.x + (parentSize.width / 2 - size.width / 2),
            parentPosition.y + (parentSize.height / 2 - size.height / 2));
    dialog.setLocation(position);
}

From source file:Main.java

public static void setCenterOfParent(JDialog parent, JDialog dialog) {
    Point parentPosition = parent.getLocation();
    Dimension parentSize = parent.getSize();
    Dimension size = dialog.getSize();
    Point position = new Point(parentPosition.x + (parentSize.width / 2 - size.width / 2),
            parentPosition.y + (parentSize.height / 2 - size.height / 2));
    dialog.setLocation(position);
}

From source file:Main.java

public static void openDialogNextToParent(final JComponent parentComponent, final JDialog dialog) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override/*from w  ww.  jav  a2s  . c  o m*/
        public void run() {
            if (parentComponent != null) {
                Point parentLocation = parentComponent.getLocationOnScreen();
                parentLocation.x += parentComponent.getWidth();
                dialog.setLocation(parentLocation);
            }
            dialog.setVisible(true);
            dialog.setSize(dialog.getPreferredSize());
        }
    });
}

From source file:com.limegroup.gnutella.gui.GUIUtils.java

/**
 * Sets the location of <tt>dialog</tt> so it appears centered regarding
 * the main application or centered on the screen if the main application is
 * not visible.//  w  w  w  .j av a  2 s . c  o  m
 */
public static void centerOnScreen(JDialog dialog) {
    if (GUIMediator.isAppVisible()) {
        dialog.setLocationRelativeTo(GUIMediator.getAppFrame());
    } else {
        dialog.setLocation(GUIMediator.getScreenCenterPoint(dialog));
    }
}

From source file:Main.java

public Main() {
    int MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

    KeyStroke exitKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, MASK);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);

    JMenu fileMenu = new JMenu("File");
    JMenuItem fileExit = new JMenuItem(exitAction);
    fileMenu.add(fileExit);//from   w  w  w  . ja  va2  s .com
    JMenuBar menu = new JMenuBar();
    menu.add(fileMenu);

    JDialog d = new JDialog(this, "Dialog");
    JPanel p = new JPanel();
    p.getInputMap().put(exitKey, exitName);
    p.getActionMap().put(exitName, exitAction);
    p.add(new JButton(exitAction));
    d.add(p);
    d.pack();
    d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    this.setJMenuBar(menu);
    this.pack();
    this.setSize(new Dimension(320, 240));
    this.setVisible(true);
    d.setLocation(this.getRootPane().getContentPane().getLocationOnScreen());
    d.setVisible(true);
}

From source file:edu.ucla.stat.SOCR.motionchart.MotionMouseListener.java

/**
 * Callback method for receiving notification of a mouse click on a chart.
 *
 * @param event information about the event.
 *//*from   w  w  w. ja  v a2  s. c o m*/
public void chartMouseClicked(ChartMouseEvent event) {
    if (event.getTrigger().getClickCount() > 1) {
        if (event.getEntity() instanceof XYItemEntity) {
            XYItemEntity item = (XYItemEntity) event.getEntity();
            Component c = event.getTrigger().getComponent();
            final JDialog dialog = new JDialog(JOptionPane.getFrameForComponent(c), "Item Data", false);
            dialog.setSize(400, 300);
            dialog.setLocation(getDialogLocation(dialog, c));
            dialog.add(getItemPanel(dialog, item, event));
            dialog.setVisible(true);
        } else {
            XYItemEntity item = (XYItemEntity) event.getEntity();
            Component c = event.getTrigger().getComponent();
            final JDialog dialog = new JDialog(JOptionPane.getFrameForComponent(c), "Item Data", false);
            dialog.setSize(400, 300);
            dialog.setLocation(getDialogLocation(dialog, c));
            dialog.add(getSeriesPanel(dialog, event));
            dialog.setVisible(true);
        }
    } else {
        if (!(event.getChart().getXYPlot().getRenderer() instanceof MotionBubbleRenderer)) {
            return;
        }

        MotionBubbleRenderer renderer = (MotionBubbleRenderer) event.getChart().getXYPlot().getRenderer();
        MotionDataSet dataset = (MotionDataSet) event.getChart().getXYPlot().getDataset();

        if (event.getEntity() instanceof XYItemEntity) {
            boolean selected;
            XYItemEntity entity = (XYItemEntity) event.getEntity();
            int series = entity.getSeriesIndex();
            int item = entity.getItem();
            Object category = dataset.getCategory(series, item);

            if (category == null) {
                selected = !renderer.isSelectedItem(series, item);
                renderer.setSelectedItem(series, item, selected);
            } else {
                selected = !renderer.isSelectedCategory(category);
                renderer.setSelectedCategory(category, selected);
            }
        }
    }
}

From source file:com.osparking.attendant.AttListForm.java

private void displayHelpDialog(JButton PWHelpButton, String title, String helpText, boolean isPassword) {
    JDialog helpDialog = new PWHelpJDialog(this, false, title, helpText, isPassword);
    int helpHt = helpDialog.getPreferredSize().height / 2;
    Point buttonLoc = getLocationOnCurrentScreen(PWHelpButton);
    Point topLeft = new Point(buttonLoc.x + 30, buttonLoc.y - helpHt);

    helpDialog.setLocation(topLeft);
    helpDialog.setVisible(true);/*from  ww  w. ja v a 2s .c om*/
}

From source file:org.accada.hal.impl.sim.GraphicSimulator.java

/**
 * creates the help menu item if it does not already exists
 * // w  w  w  . ja  v a2  s.c  om
 * @return help menu
 */
private JMenu getHelpMenu() {
    JMenu helpMenu = new JMenu(guiTextConfig.getString("HelpMenuItem"));

    // about
    JMenuItem aboutMenuItem = new JMenuItem();
    aboutMenuItem.setText(guiTextConfig.getString("AboutMenuItem"));
    aboutMenuItem.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent e) {
            JDialog aboutDialog = new JDialog(GraphicSimulator.this,
                    guiTextConfig.getString("AboutDialogTitle"), true);
            Point pos = new Point();
            pos.x = jLayeredPane.getLocationOnScreen().x
                    + (jLayeredPane.getWidth() - getProperty("DialogWindowWidth")) / 2;
            pos.y = jLayeredPane.getLocationOnScreen().y
                    + (jLayeredPane.getHeight() - getProperty("DialogWindowHeight")) / 2;
            aboutDialog.setLocation(pos);
            aboutDialog.setSize(getProperty("DialogWindowWidth"), getProperty("DialogWindowHeight"));
            aboutDialog.setTitle(guiTextConfig.getString("AboutDialogTitle"));
            JLabel text = new JLabel(guiTextConfig.getString("AboutDialogContent"));
            text.setHorizontalAlignment(JLabel.CENTER);
            aboutDialog.add(text);
            aboutDialog.setVisible(true);
        }
    });
    helpMenu.add(aboutMenuItem);
    return helpMenu;
}

From source file:org.accada.hal.impl.sim.multi.GraphicSimulatorServer.java

/**
 * creates the help menu item//ww w .  j  a  va  2 s . c om
 * 
 * @return help menu
 */
private JMenu getHelpMenu() {
    JMenu helpMenu = new JMenu(guiTextConfig.getString("HelpMenuItem"));

    // about
    JMenuItem aboutMenuItem = new JMenuItem();
    aboutMenuItem.setText(guiTextConfig.getString("AboutMenuItem"));
    aboutMenuItem.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent e) {
            JDialog aboutDialog = new JDialog(GraphicSimulatorServer.this,
                    guiTextConfig.getString("AboutDialogTitle"), true);
            Point pos = new Point();
            pos.x = jLayeredPane.getLocationOnScreen().x
                    + (jLayeredPane.getWidth() - getProperty("DialogWindowWidth")) / 2;
            pos.y = jLayeredPane.getLocationOnScreen().y
                    + (jLayeredPane.getHeight() - getProperty("DialogWindowHeight")) / 2;
            aboutDialog.setLocation(pos);
            aboutDialog.setSize(getProperty("DialogWindowWidth"), getProperty("DialogWindowHeight"));
            aboutDialog.setTitle(guiTextConfig.getString("AboutDialogTitle"));
            JLabel text = new JLabel(guiTextConfig.getString("AboutDialogContent"));
            text.setHorizontalAlignment(JLabel.CENTER);
            aboutDialog.add(text);
            aboutDialog.setVisible(true);
        }
    });
    helpMenu.add(aboutMenuItem);
    return helpMenu;
}

From source file:org.accada.reader.hal.impl.sim.GraphicSimulator.java

/**
 * creates the help menu item if it does not already exists
 * /* w  ww.  j  av  a  2  s  .c  om*/
 * @return help menu
 */
private JMenu getHelpMenu() {
    JMenu helpMenu = new JMenu(guiText.getString("HelpMenuItem"));

    // about
    JMenuItem aboutMenuItem = new JMenuItem();
    aboutMenuItem.setText(guiText.getString("AboutMenuItem"));
    aboutMenuItem.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent e) {
            JDialog aboutDialog = new JDialog(GraphicSimulator.this, guiText.getString("AboutDialogTitle"),
                    true);
            Point pos = new Point();
            pos.x = jLayeredPane.getLocationOnScreen().x
                    + (jLayeredPane.getWidth() - getProperty("DialogWindowWidth")) / 2;
            pos.y = jLayeredPane.getLocationOnScreen().y
                    + (jLayeredPane.getHeight() - getProperty("DialogWindowHeight")) / 2;
            aboutDialog.setLocation(pos);
            aboutDialog.setSize(getProperty("DialogWindowWidth"), getProperty("DialogWindowHeight"));
            aboutDialog.setTitle(guiText.getString("AboutDialogTitle"));
            JLabel text = new JLabel(guiText.getString("AboutDialogContent"));
            text.setHorizontalAlignment(JLabel.CENTER);
            aboutDialog.add(text);
            aboutDialog.setVisible(true);
        }
    });
    helpMenu.add(aboutMenuItem);
    return helpMenu;
}