Example usage for javax.swing JDialog setLocationRelativeTo

List of usage examples for javax.swing JDialog setLocationRelativeTo

Introduction

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

Prototype

public void setLocationRelativeTo(Component c) 

Source Link

Document

Sets the location of the window relative to the specified component according to the following scenarios.

Usage

From source file:es.udc.fic.medregatas.view.MainAppjFrame.java

private void NewTipoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NewTipoMenuItemActionPerformed
    Tipo aEditar = null;/*from ww w.j a v a2 s  .  com*/
    JDialog dialog = new NuevoTipoJDialog(this, true, aEditar);
    dialog.setLocationRelativeTo(null);
    dialog.setVisible(true);

}

From source file:es.udc.fic.medregatas.view.MainAppjFrame.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    JDialog dialog = new RegistrarDatosRegataJDialog(this, null);
    dialog.setLocationRelativeTo(null);
    dialog.setVisible(true);// ww  w .  ja v  a 2  s.  c  om
    regatasList.setListData(regataService.getRegatas().toArray());
}

From source file:es.udc.fic.medregatas.view.MainAppjFrame.java

private void newRegataMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newRegataMenuItemActionPerformed

    JDialog dialog = new RegistrarDatosRegataJDialog(this, null);
    dialog.setLocationRelativeTo(null);
    dialog.setVisible(true);/*from   ww  w  .j av a 2  s .  c  o  m*/
    regatasList.setListData(regataService.getRegatas().toArray());
}

From source file:org.nekorp.workflow.desktop.view.resource.imp.ServicioPreviewDialogFactory.java

@Override
public JDialog createDialog(Frame frame, boolean modal) {
    JDialog dialog = new JDialog(mainFrame, true);
    dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    dialog.setTitle("Consulta Servicio " + " Nmero: " + viewServicioModel.getId());
    servicioPreview.setParent(dialog);/* ww  w  .ja  v a  2s .  c  o m*/
    servicioPreview.iniciaVista();
    servicioPreview.setEditableStatus(false);
    dialog.add(servicioPreview);
    dialog.validate();
    dialog.pack();
    dialog.setLocationRelativeTo(mainFrame);
    return dialog;
}

From source file:net.lmxm.ute.gui.validation.AbstractInputValidator.java

/**
 * Display messages dialog.//  w w  w .j  a  va 2  s. c  om
 * 
 * @param component the component
 * @param messages the messages
 */
private void displayMessagesDialog(final JComponent component, final List<String> messages) {
    final JDialog dialog = getMessagesDialog();

    // Load dialog with messages.
    getMessagesLabel().setText(StringUtils.join(messages, "\n"));

    // Relocate dialog relative to the input component
    dialog.setSize(0, 0);
    dialog.setLocationRelativeTo(component);
    final Point location = dialog.getLocation();
    final Dimension componentSize = component.getSize();
    dialog.setLocation(location.x - (int) componentSize.getWidth() / 2,
            location.y + (int) componentSize.getHeight() / 2);
    dialog.pack();
    dialog.setVisible(true);
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.ChartDisplayPanel.java

/**
 * Creates a dialog window which contains the chart in its preferred size.
 *///from  ww  w.  j a  v  a2s . com
private void displayEnlarged() {
    JDialog dialog = new JDialog(ownerDialog, visualizer.getTitle(), false);
    dialog.getContentPane().add(JFreeChartConn.createPanel(chart));
    dialog.pack();
    dialog.setLocationRelativeTo(ownerDialog);
    dialog.setVisible(true);
}

From source file:com.floreantpos.config.ui.TerminalConfigurationView.java

public void restartPOS() {
    JOptionPane optionPane = new JOptionPane(Messages.getString("TerminalConfigurationView.26"), //$NON-NLS-1$
            JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, Application.getApplicationIcon(),
            new String[] { /*Messages.getString("TerminalConfigurationView.28"),*/Messages
                    .getString("TerminalConfigurationView.30") }); //$NON-NLS-1$ //$NON-NLS-2$

    Object[] optionValues = optionPane.getComponents();
    for (Object object : optionValues) {
        if (object instanceof JPanel) {
            JPanel panel = (JPanel) object;
            Component[] components = panel.getComponents();

            for (Component component : components) {
                if (component instanceof JButton) {
                    component.setPreferredSize(new Dimension(100, 80));
                    JButton button = (JButton) component;
                    button.setPreferredSize(PosUIManager.getSize(100, 50));
                }/*w  w w  . j  ava 2s .co  m*/
            }
        }
    }
    JDialog dialog = optionPane.createDialog(Application.getPosWindow(),
            Messages.getString("TerminalConfigurationView.31")); //$NON-NLS-1$
    dialog.setIconImage(Application.getApplicationIcon().getImage());
    dialog.setLocationRelativeTo(Application.getPosWindow());
    dialog.setVisible(true);
    Object selectedValue = (String) optionPane.getValue();
    if (selectedValue != null) {

        if (selectedValue.equals(Messages.getString("TerminalConfigurationView.28"))) { //$NON-NLS-1$
            try {
                Main.restart();
            } catch (IOException | InterruptedException | URISyntaxException e) {
            }
        } else {
        }
    }

}

From source file:com.ln.gui.Main.java

public void swingupd() {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                String av = "Updates available!";
                JOptionPane pane1 = new JOptionPane(av, JOptionPane.WARNING_MESSAGE,
                        JOptionPane.DEFAULT_OPTION);
                JDialog dialog1 = pane1.createDialog("Update");
                dialog1.setLocationRelativeTo(null);
                dialog1.setVisible(true);
                dialog1.setAlwaysOnTop(true);
                Updatechecker upd = new Updatechecker();
                upd.setVisible(true);//from  w  ww.  ja  va2  s.c o  m
                upd.setLocationRelativeTo(rootPane);
                upd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            } catch (Exception e) {
            }
        }
    });
}

From source file:Main.java

/**
 * Initialises the {@link JDialog} for the {@link JComponent}.
 * //from w  w  w  . j  av  a 2s .  co  m
 * @param dialog
 * @param component
 * @param parentComponent
 */
private static void initDialog(final JDialog dialog, final JComponent component,
        final Component parentComponent) {
    dialog.setResizable(true);
    dialog.setComponentOrientation(component.getComponentOrientation());
    Container contentPane = dialog.getContentPane();

    contentPane.setLayout(new BorderLayout());
    contentPane.add(component, BorderLayout.CENTER);

    final int buttonWidth = 75;

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(2, 4, 4, 4));

    buttonPanel.add(Box.createHorizontalGlue());

    @SuppressWarnings("serial")
    final Action closeAction = new AbstractAction("Close") {
        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };

    final JButton button = new JButton(closeAction);
    fixWidth(button, buttonWidth);
    buttonPanel.add(button);

    contentPane.add(buttonPanel, BorderLayout.SOUTH);

    if (JDialog.isDefaultLookAndFeelDecorated()) {
        boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations();
        if (supportsWindowDecorations) {
            dialog.setUndecorated(true);
            component.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
        }
    }
    dialog.pack();
    dialog.setLocationRelativeTo(parentComponent);
    WindowAdapter adapter = new WindowAdapter() {
        //         private boolean gotFocus = false;
        public void windowClosing(WindowEvent we) {
            fireAction(we.getSource(), closeAction, "close");
        }
    };
    dialog.addWindowListener(adapter);
    dialog.addWindowFocusListener(adapter);
}

From source file:net.phyloviz.project.action.LoadDataSetAction.java

private JDialog createLoadingDialog() {
    JDialog d = new JDialog(WindowManager.getDefault().getMainWindow(), null, true);
    d.setLayout(new GridBagLayout());
    JPanel panel = new JPanel();
    JLabel jlabel = new JLabel("Loading DataSet.....");
    jlabel.setFont(new Font("Verdana", 1, 14));
    panel.add(jlabel);/*from ww  w . j  av  a  2 s.  c  om*/
    d.add(panel, new GridBagConstraints());
    d.setSize(200, 50);
    d.setLocationRelativeTo(null);
    d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    return d;
}