javax.swing.JDialog#setLocationRelativeTo ( )源码实例Demo

下面列出了javax.swing.JDialog#setLocationRelativeTo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: CodenameOne   文件: AddThemeEntry.java
private void imageBorderWizardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imageBorderWizardActionPerformed
    deriveBorder.setSelected(false);
    ImageBorderWizardTabbedPane iw = new ImageBorderWizardTabbedPane(resources, themeName);
    String name = (String)componentName.getSelectedItem();
    String uiid;
    if(prefix == null || prefix.length() == 0) {
        uiid = name + ".border";
    } else {
        uiid = name + "." + prefix + "border";
    }
    iw.addToAppliesToList(uiid);
    JDialog dlg = new JDialog(SwingUtilities.windowForComponent(this));
    dlg.setLayout(new java.awt.BorderLayout());
    dlg.add(java.awt.BorderLayout.CENTER, iw);
    dlg.pack();
    dlg.setLocationRelativeTo(this);
    dlg.setModal(true);
    dlg.setVisible(true);
    Border b = (Border)resources.getTheme(themeName).get(uiid);
    if(b != null) {
        currentBorder = b;
        ((CodenameOneComponentWrapper)borderLabel).getCodenameOneComponent().getStyle().setBorder(b);
        borderLabel.repaint();
    }
}
 
源代码2 项目: hortonmachine   文件: ImageViewer.java
/**
 * Opens a JDialog with the image viewer in it.
 * 
 * @param image the image to show.
 * @param title the title of the dialog.
 * @param modal if <code>true</code>, the dialog is modal.
 */
public static void show( BufferedImage image, String title, boolean modal ) {
    JDialog f = new JDialog();
    f.add(new ImageViewer(image), BorderLayout.CENTER);
    f.setTitle(title);
    f.setIconImage(ImageCache.getInstance().getBufferedImage(ImageCache.HORTONMACHINE_FRAME_ICON));
    f.setModal(modal);
    f.pack();
    int h = image.getHeight();
    int w = image.getWidth();
    if (h > w) {
        f.setSize(new Dimension(600, 800));
    } else {
        f.setSize(new Dimension(800, 600));
    }
    f.setLocationRelativeTo(null); // Center on screen
    f.setVisible(true);
    f.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    f.getRootPane().registerKeyboardAction(e -> {
        f.dispose();
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
}
 
源代码3 项目: CodenameOne   文件: ThemeEditor.java
private void borderWizardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_borderWizardActionPerformed
    ImageBorderWizardTabbedPane iw = new ImageBorderWizardTabbedPane(resources, themeName);
    JDialog dlg = new JDialog(SwingUtilities.windowForComponent(this), "Border Wizard");
    dlg.setLayout(new java.awt.BorderLayout());
    dlg.add(java.awt.BorderLayout.CENTER, iw);
    dlg.pack();
    dlg.setLocationRelativeTo(this);
    dlg.setModal(true);
    dlg.setVisible(true);
    themeHash = resources.getTheme(themeName);
    initTableModel(theme, null);
    initTableModel(selectedStyles, "sel#");
    initTableModel(pressedStyles, "press#");
    initTableModel(disabledStyles, "dis#");
    refreshTheme(themeHash);
}
 
源代码4 项目: PacketProxy   文件: JFontChooser.java
protected JDialog createDialog(Component parent) {
    Frame frame = parent instanceof Frame ? (Frame) parent
        : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
    JDialog dialog = new JDialog(frame, I18nString.get("Font Setting"), true);

    Action okAction = new DialogOKAction(dialog);
    Action cancelAction = new DialogCancelAction(dialog);

    JButton okButton = new JButton(okAction);
    okButton.setFont(DEFAULT_FONT);
    JButton cancelButton = new JButton(cancelAction);
    cancelButton.setFont(DEFAULT_FONT);

    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new GridLayout(2, 1));
    buttonsPanel.add(okButton);
    buttonsPanel.add(cancelButton);
    buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10));

    ActionMap actionMap = buttonsPanel.getActionMap();
    actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction);
    actionMap.put(okAction.getValue(Action.DEFAULT), okAction);
    InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT));
    inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT));

    JPanel dialogEastPanel = new JPanel();
    dialogEastPanel.setLayout(new BorderLayout());
    dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH);

    dialog.getContentPane().add(this, BorderLayout.CENTER);
    dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST);
    dialog.pack();
    dialog.setLocationRelativeTo(frame);
    return dialog;
}
 
源代码5 项目: MeteoInfo   文件: FrmMain.java
private void jMenuItem_ColorDialogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_ColorDialogActionPerformed
    // TODO add your handling code here:
    JDialog colorMapDialog = new JDialog(this, false);
    colorMapDialog.setTitle("Color Dialog");
    colorMapDialog.setFocusableWindowState(false);
    colorMapDialog.add(new JColorChooser(Color.black));
    colorMapDialog.setSize(600, 400);
    colorMapDialog.setLocationRelativeTo(this);
    colorMapDialog.setVisible(true);
}
 
源代码6 项目: Spark   文件: TransferManager.java
/**
 * Displays the transfer dialog.
 *
 * @param parent the parent frame.
 * @return the number selected, if available. Otherwise null is returned.
 */
public String getNumber(JFrame parent) {
    dialog = new JDialog(parent, "Transfer Call", true);
    dialog.setLocationRelativeTo(parent);
    dialog.getContentPane().setLayout(new BorderLayout());
    dialog.getContentPane().add(this, BorderLayout.CENTER);
    dialog.pack();
    dialog.setSize(350, 400);
    dialog.setVisible(true);
    return dialedNumber;
}
 
源代码7 项目: FastDMM   文件: ModifiedType.java
public boolean viewVariables(FastDMM editor) {
	final JDialog dialog = new JDialog(editor, "View Variables", true);
	
	final ModifiedTypeTableModel model = new ModifiedTypeTableModel(this);
	JTable table = new JTable(model);
	table.setFillsViewportHeight(true);
	table.setDefaultRenderer(Object.class, new ModifiedTypeRenderer(model));
	dialog.getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
	
	JPanel bottomPanel = new JPanel(new BorderLayout());
	dialog.getContentPane().add(bottomPanel, BorderLayout.SOUTH);
	
	JButton okButton = new JButton("OK");
	okButton.addActionListener(e -> {
           model.doReturnTrue = true;
           dialog.setVisible(false);
       });
	bottomPanel.add(okButton, BorderLayout.WEST);
	
	JButton cancelButton = new JButton("Cancel");
	cancelButton.addActionListener(e -> dialog.setVisible(false));
	bottomPanel.add(cancelButton, BorderLayout.EAST);
	
	dialog.setLocationRelativeTo(editor);
	dialog.setSize(400, 450);
	dialog.setPreferredSize(dialog.getSize());
	dialog.setVisible(true);
	
	return model.doReturnTrue;
}
 
源代码8 项目: RipplePower   文件: VerifyDialog.java
public static void showDialog(JDialog parent) {
	try {
		JDialog dialog = new VerifyDialog(parent);
		dialog.pack();
		dialog.setLocationRelativeTo(parent);
		dialog.setVisible(true);
	} catch (Exception exc) {
		ErrorLog.get().logException("Exception while displaying dialog", exc);
	}
}
 
源代码9 项目: wandora   文件: PingerPanel.java
protected void openInOwnWindow(Wandora w) {
    JDialog dialog = new JDialog(w, false);
    dialog.add(this);
    dialog.setSize(600, 380);
    dialog.setMinimumSize(new Dimension(600, 380));
    dialog.setLocationRelativeTo(w);
    dialog.setVisible(true);
    dialog.setTitle(PANEL_TITLE);
}
 
源代码10 项目: pumpernickel   文件: QOptionPane.java
/**
 * 
 * @param owner
 * @param useSheets
 *            if this is true then sheets should be used to display this
 *            dialog. Note this is only supported in Java 1.6+.
 */
public int showDialog(Frame owner, boolean useSheets) {
	DialogFooter footer = getDialogFooter();
	if (footer != null)
		footer.reset();
	String dialogTitle = getDialogTitle();
	JDialog dialog = new JDialog(owner, dialogTitle, true);
	if (useSheets && JVM.getMajorJavaVersion() >= 1.6f) {
		Reflection
				.invokeMethod(Dialog.class, dialog, "setModalityType",
						new Object[] { Reflection.getFieldValue(
								"java.awt.Dialog$ModalityType",
								"DOCUMENT_MODAL") });
		dialog.getRootPane().putClientProperty(
				"apple.awt.documentModalSheet", new Boolean(useSheets));
	}
	dialog.getContentPane().add(createDebugPanel());
	dialog.setResizable(false);
	dialog.pack();
	dialog.setLocationRelativeTo(owner);
	dialog.setVisible(true);
	if (footer != null) {
		JComponent jc = footer.getLastSelectedComponent();
		Integer i = (Integer) jc
				.getClientProperty(DialogFooter.PROPERTY_OPTION);
		if (i != null)
			return i.intValue();
	}
	return JComponent.UNDEFINED_CONDITION;
}
 
源代码11 项目: Spark   文件: ChatTranscriptPlugin.java
private void showStatusMessage(ContactItem item)
{
 Frame = new JDialog();
 Frame.setTitle(item.getDisplayName() + " - Status");
 JPanel pane = new JPanel();
 JTextArea textArea = new JTextArea(5, 30);
 JButton btn_close = new JButton(Res.getString("button.close"));

 btn_close.addActionListener( e -> Frame.setVisible(false) );

 textArea.setLineWrap(true);
 textArea.setWrapStyleWord(true);

 pane.add(new JScrollPane(textArea));
 Frame.setLayout(new BorderLayout());
 Frame.add(pane, BorderLayout.CENTER);
 Frame.add(btn_close, BorderLayout.SOUTH);

 textArea.setEditable(false);
 textArea.setText(item.getStatus());

 Frame.setLocationRelativeTo(SparkManager.getMainWindow());
 Frame.setBounds(Frame.getX() - 175, Frame.getY() - 75, 350, 150);
 Frame.setSize(350, 150);
 Frame.setResizable(false);
 Frame.setVisible(true);
}
 
源代码12 项目: GpsPrune   文件: GenericProgressDialog.java
/**
 * Create the dialog to show the progress
 */
private void createProgressDialog()
{
	_progressDialog = new JDialog(_parentFrame, I18nManager.getText(_dialogTitleKey));
	_progressDialog.setLocationRelativeTo(_parentFrame);
	_progressBar = new JProgressBar(0, 100);
	_progressBar.setValue(0);
	_progressBar.setStringPainted(true);
	_progressBar.setString("");
	JPanel panel = new JPanel();
	panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
	panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
	panel.add(new JLabel(I18nManager.getText(_labelKey)));
	panel.add(_progressBar);
	panel.add(Box.createVerticalStrut(6)); // spacer
	JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
	cancelButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e)
		{
			_function.cancel();
		}
	});
	panel.add(cancelButton);
	_progressDialog.getContentPane().add(panel);
	_progressDialog.pack();
	_progressDialog.setVisible(true);
}
 
源代码13 项目: CodenameOne   文件: AddThemeEntry.java
private void customizeBorderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customizeBorderActionPerformed
    BorderEditor editor = new BorderEditor(currentBorder, resources);
    JDialog dialog = new JDialog((JDialog)SwingUtilities.windowForComponent(this), "Border");
    dialog.setLayout(new BorderLayout());
    dialog.add(BorderLayout.CENTER, editor);
    dialog.pack();
    dialog.setLocationRelativeTo(customizeBorder);
    dialog.setModal(true);
    dialog.setVisible(true);
    currentBorder = editor.getResult();
    updateThemePreview();
}
 
源代码14 项目: lucene-solr   文件: CreateIndexDialogFactory.java
@Override
public JDialog create(Window owner, String title, int width, int height) {
  dialog = new JDialog(owner, title, Dialog.ModalityType.APPLICATION_MODAL);
  dialog.add(content());
  dialog.setSize(new Dimension(width, height));
  dialog.setLocationRelativeTo(owner);
  dialog.getContentPane().setBackground(prefs.getColorTheme().getBackgroundColor());
  return dialog;
}
 
源代码15 项目: lucene-solr   文件: TermVectorDialogFactory.java
@Override
public JDialog create(Window owner, String title, int width, int height) {
  if (Objects.isNull(field) || Objects.isNull(tvEntries)) {
    throw new IllegalStateException("field name and/or term vector is not set.");
  }

  dialog = new JDialog(owner, title, Dialog.ModalityType.APPLICATION_MODAL);
  dialog.add(content());
  dialog.setSize(new Dimension(width, height));
  dialog.setLocationRelativeTo(owner);
  dialog.getContentPane().setBackground(prefs.getColorTheme().getBackgroundColor());
  return dialog;
}
 
源代码16 项目: RipplePower   文件: ReceiveAddressDialog.java
public static void showDialog(JDialog parent) {
	try {
		JDialog dialog = new ReceiveAddressDialog(parent);
		dialog.pack();
		dialog.setLocationRelativeTo(parent);
		dialog.setVisible(true);
	} catch (Exception exc) {
		ErrorLog.get().logException("Exception while displaying dialog", exc);
	}
}
 
源代码17 项目: GpsPrune   文件: AddMapSourceDialog.java
/**
 * Constructor
 * @param inParent parent dialog
 */
public AddMapSourceDialog(JDialog inParentDialog, SetMapBgFunction inParentFunction)
{
	_parent = inParentFunction;
	_addDialog = new JDialog(inParentDialog, I18nManager.getText("dialog.addmapsource.title"), true);
	_addDialog.add(makeDialogComponents());
	_addDialog.setLocationRelativeTo(inParentDialog);
	_addDialog.pack();
}
 
源代码18 项目: PolyGlot   文件: JFontChooser.java
protected JDialog createDialog(Component parent)
{
    double menuFontSize = core.getOptionsManager().getMenuFontSize();
    boolean nightMode = core.getOptionsManager().isNightMode();
    Frame frame = parent instanceof Frame ? (Frame) parent
        : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
    JDialog dialog = new JDialog(frame, ("Select Font"), true);

    frame.setBackground(Color.white);
    Action okAction = new DialogOKAction(dialog);
    Action cancelAction = new DialogCancelAction(dialog);

    PButton okButton = new PButton(nightMode, menuFontSize);
    okButton.setAction(okAction);
    okButton.setFont(DEFAULT_FONT);
    PButton cancelButton = new PButton(nightMode, menuFontSize);
    cancelButton.setAction(cancelAction);
    cancelButton.setFont(DEFAULT_FONT);

    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setBackground(Color.white);
    buttonsPanel.setLayout(new GridLayout(2, 1));
    buttonsPanel.add(okButton);
    buttonsPanel.add(cancelButton);
    buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10));

    ActionMap actionMap = buttonsPanel.getActionMap();
    actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction);
    actionMap.put(okAction.getValue(Action.DEFAULT), okAction);
    InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT));
    inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT));

    JPanel dialogEastPanel = new JPanel();
    dialogEastPanel.setBackground(Color.white);
    dialogEastPanel.setLayout(new BorderLayout());
    dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH);

    dialog.getContentPane().add(this, BorderLayout.CENTER);
    dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST);
    dialog.pack();
    dialog.setLocationRelativeTo(frame);
    dialog.getRootPane().setBackground(Color.white);
    return dialog;
}
 
源代码19 项目: triplea   文件: ProLogWindow.java
private void settingsDetailsButtonActionPerformed() {
  final JDialog dialog = new JDialog(this, "Pro AI - Settings Details");
  String message = "";
  if (tabPaneMain.getSelectedIndex() == 0) { // Debugging
    message =
        "Debugging\r\n"
            + "\r\n"
            + "AI Logging: When this is checked, the AI's will output their logs, as they come "
            + "in, so you can see exactly what the AI is thinking.\r\n"
            + "Note that if you check this on, you still have to press OK then reopen the "
            + "settings window for the logs to actually start displaying.\r\n"
            + "\r\n"
            + "Log Depth: This setting lets you choose how deep you want the AI logging to be. "
            + "Fine only displays the high-level events, like the start of a phase, etc.\r\n"
            + "Finer displays medium-level events, such as attacks, reinforcements, etc.\r\n"
            + "Finest displays all the AI logging available. Can be used for detailed analysis, "
            + "but is a lot harder to read through it.\r\n"
            + "\r\n"
            + "Pause AI's: This checkbox pauses all the AI's while it's checked, so you can look "
            + "at the logs without the AI's outputting floods of information.\r\n"
            + "\r\n"
            + "Limit Log History To X Rounds: If this is checked, the AI log information will "
            + "be limited to X rounds of information.\r\n";
  }
  final JTextArea label = new JTextArea(message);
  label.setFont(new Font("Segoe UI", Font.PLAIN, 12));
  label.setEditable(false);
  label.setAutoscrolls(true);
  label.setLineWrap(false);
  label.setFocusable(false);
  label.setWrapStyleWord(true);
  label.setLocation(0, 0);
  dialog.setBackground(label.getBackground());
  dialog.setLayout(new BorderLayout());
  final JScrollPane pane = new JScrollPane();
  pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
  pane.setViewportView(label);
  dialog.add(pane, BorderLayout.CENTER);
  final JButton button = new JButton("Close");
  button.setMinimumSize(new Dimension(100, 30));
  button.addActionListener(e -> dialog.dispose());
  dialog.add(button, BorderLayout.SOUTH);
  dialog.setMinimumSize(new Dimension(500, 300));
  dialog.setSize(new Dimension(800, 600));
  dialog.setResizable(true);
  dialog.setLocationRelativeTo(this);
  dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  dialog.setVisible(true);
}
 
源代码20 项目: visualvm   文件: StartupDialog.java
public static JDialog create(String caption, String message, int messageType) {
    // Bugfix #361, set the JDialog to appear in the Taskbar on Windows (ModalityType.APPLICATION_MODAL)
    Window[] windows = Window.getWindows();
    final JDialog d = windows == null || windows.length == 0 ?
            new JDialog(null, caption, JDialog.ModalityType.APPLICATION_MODAL) :
            new JDialog((Frame)null, caption, true);
    
    if (message != null) initDialog(d, message, messageType);
    
    // Bugfix #361, JDialog should use the VisualVM icon for better identification
    List<Image> icons = new ArrayList();
    icons.add(ImageUtilities.loadImage("org/netbeans/core/startup/frame.gif", true)); // NOI18N
    icons.add(ImageUtilities.loadImage("org/netbeans/core/startup/frame24.gif", true)); // NOI18N
    icons.add(ImageUtilities.loadImage("org/netbeans/core/startup/frame32.gif", true)); // NOI18N
    icons.add(ImageUtilities.loadImage("org/netbeans/core/startup/frame48.gif", true)); // NOI18N
    d.setIconImages(icons);
    
    d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    d.setResizable(false);
    d.setLocationRelativeTo(null);
    
    // Bugfix #361, ensure that the dialog will be the topmost visible window after opening
    d.addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                if (d.isShowing()) {
                    // For some reason the dialog created with defined JDialog.ModalityType
                    // isn't displayed on Windows when opened by the NetBeans launcher. This
                    // code seems to workaround it while not breaking anything elsewhere.
                    // Disabled to fix jigsaw, the problem is not reproducible using [email protected]
                    // ComponentPeer peer = d.getPeer();
                    // if (peer != null) peer.setVisible(true);

                    d.removeHierarchyListener(this);
                    d.setAlwaysOnTop(true);
                    d.toFront();
                    d.setAlwaysOnTop(false);
                }
            }
        }
    });
    
    return d;
}