/** * Centers the dialog within its parent window. */ public void center() { UIUtils.centerComponent(dialog, parent); }
/** * Centers the given component within the screen area. * <p/> * <p> The method performs the alignment by setting a newly computed location for the component. It does not alter * the component's size. * * @param comp the component whose location is to be altered * * @throws IllegalArgumentException if the component is <code>null</code> */ public static void centerComponent(Component comp) { centerComponent(comp, null); }
public void center() { UIUtils.centerComponent(dialog, frame); }
/** * Centers this application frame within the screen area. */ public final void center() { UIUtils.centerComponent(getMainFrame()); }
private JDialog createOptionsWindow() { form = new MagicWandForm(this); JDialog optionsWindow = new JDialog(VisatApp.getApp().getMainFrame(), DIALOG_TITLE, false); UIUtils.centerComponent(optionsWindow, VisatApp.getApp().getMainFrame()); optionsWindow.getContentPane().add(form.createPanel()); optionsWindow.pack(); return optionsWindow; }
/** * Displays the dialog if this {@code AssistantPane} with * the given {@link AssistantPage page} as first page. * * @param firstPage The first page which is displayed in the dialog. * @param bounds The screen bounds of the window, may be {@code null}. */ public void show(AssistantPage firstPage, Rectangle bounds) { initPage(firstPage); setCurrentPage(firstPage); if (bounds == null) { dialog.setSize(480, 320); UIUtils.centerComponent(dialog, dialog.getParent()); } else { dialog.setBounds(bounds); } dialog.setVisible(true); }
@Test public void testCenterComponent() { try { Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); Component comp = new Panel(); Component alignComp = new Panel(); comp.setBounds(0, 0, 100, 100); UIUtils.centerComponent(comp); assertEquals(comp.getBounds(), new Rectangle(screenSize.width / 2 - 50, screenSize.height / 2 - 50, 100, 100)); comp.setBounds(0, 0, 100, 100); alignComp.setBounds(100, 100, 200, 200); UIUtils.centerComponent(comp, alignComp); assertEquals(comp.getBounds(), new Rectangle(150, 150, 100, 100)); } catch (HeadlessException e) { warnHeadless(); } }