final JDialog d = new JDialog(); d.setSize(200, 200); final Toolkit toolkit = Toolkit.getDefaultToolkit(); final Dimension screenSize = toolkit.getScreenSize(); final int x = (screenSize.width - d.getWidth()) / 2; final int y = (screenSize.height - d.getHeight()) / 2; d.setLocation(x, y); d.setVisible(true);
public void about() { aboutBox.setSize(360, 240); aboutBox.setLocation((int)this.getLocation().getX() + 22, (int)this.getLocation().getY() + 22); aboutBox.setResizable(false); aboutBox.setVisible(true); }
dialog.setLocation(location); final JList fileList = new JList(new Vector<>(files)); fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
public void setLocation(int x, int y) { if(dialog!=null) { dialog.setLocation(x, y); } locationX = x; locationY = y; }
static class MyChooser extends JFileChooser { protected JDialog createDialog(Component parent) throws HeadlessException { JDialog dlg = super.createDialog(parent); dlg.setLocation(20, 20); return dlg; } }
/** * Shows the dialog at the given screen location. * @param x the dialogs location * @param y the dialogs location */ public void open( int x, int y ){ dialog.pack(); dialog.setLocation( x, y ); validateBounds(); dialog.setVisible( true ); }
protected JDialog createDialog(Component parent) throws HeadlessException { dialog = super.createDialog(parent); dialog.setLocation(locationX, locationY); return dialog; }
/** * Center JDialog. */ public static void center(JDialog dialog) { Dimension dialogSize = dialog.getSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); dialog.setLocation((screenSize.width - dialogSize.width) >> 1, (screenSize.height - dialogSize.height) >> 1); }
/** * Description of the Method * * @param frame PARAM */ public static void center(JDialog frame) { //p("centering"); Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((int) ((screen_size.getWidth() - frame.getWidth()) / 2), (int) ((screen_size.getHeight() - frame.getHeight()) / 2)); }
/** * Description of the Method * * @param frame PARAM */ public static void center(JDialog frame) { //p("centering"); Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((int) ((screen_size.getWidth() - frame.getWidth()) / 2), (int) ((screen_size.getHeight() - frame.getHeight()) / 2)); }
JOptionPane pane = new JOptionPane("Message", JOptionPane.WARNING_MESSAGE, JOptionPane.DEFAULT_OPTION); JDialog dialog = pane.createDialog("TITLE"); dialog.setLocation(0, 0); dialog.setVisible(true); // dialog box shown here dialog.dispose(); Object selection = pane.getValue();
@Override public void mouseDragged(MouseEvent e) { if (dragEvent != null) { d.setLocation(d.getLocation().x + (e.getX() - dragEvent.getX()), d.getLocation().y + (e.getY() - dragEvent.getY())); } dragEvent = e; } }
JOptionPane pane = new JOptionPane(arguments); pane.set.Xxxx(...); // Configure JDialog dialog = pane.createDialog(parentComponent, title); dialog.setLocation(....); // added! dialog.setModal(....); // added! Do you want it modal or not? // .... dialog.setVisible(true);
public static void setDialogLocationRelativeTo(final JDialog dialog, final Component c) { if (c == null || ! c.isShowing()) { return; } final Point location = findBestLocation(dialog, c); dialog.setLocation(location); }
/** * Place the suggestion window under the JTextField. */ private void updateLocation() { try { location = getLocationOnScreen(); location.y += getHeight(); dialog.setLocation(location); } catch (IllegalComponentStateException e) { return; // might happen on window creation } }
JOptionPane pane = new JOptionPane("Message", JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, null); pane.setWantsInput(true); JDialog dialog = pane.createDialog(null, "Title"); dialog.setLocation(0, 0); dialog.setVisible(true); String str = (String) pane.getInputValue();
private static void resizePopup() { popupWindow.pack(); Point point = new Point(0,0); SwingUtilities.convertPointToScreen(point, getMainWindow()); popupWindow.setLocation( point.x + (getMainWindow().getWidth() - popupWindow.getWidth()) / 2, point.y + (getMainWindow().getHeight() - popupWindow.getHeight()) / 3); }
private static void resizePopup() { popupWindow.pack(); Point point = new Point(0,0); SwingUtilities.convertPointToScreen(point, getMainWindow()); popupWindow.setLocation( point.x + (getMainWindow().getWidth() - popupWindow.getWidth()) / 2, point.y + (getMainWindow().getHeight() - popupWindow.getHeight()) / 3); }
private static void resizePopup() { popupWindow.pack(); Point point = new Point(0, 0); SwingUtilities.convertPointToScreen(point, getMainWindow()); popupWindow.setLocation(point.x + (getMainWindow().getWidth() - popupWindow.getWidth()) / 2, point.y + (getMainWindow().getHeight() - popupWindow.getHeight()) / 3); } private static final int X_INSET = 10;
public static void centerDialog(Frame parent, JDialog dialog) { if(parent != null && dialog != null) { dialog.setLocation(parent.getLocation().x + (parent.getSize().width - dialog.getSize().width) / 2, parent.getLocation().y + (parent.getSize().height - dialog.getSize().height) / 2); } } }