/** * Use this static method if you want to center and set its position * compared to the size of the current users screen size. Valid percent is * between +-(0-100) minus is treated as plus, bigger than 100 is always set * to 100. * * @param component * the component you want to center and set size on * @param percentOfScreen * the percent of the current screensize you want the component * to be */ public static void centerComponentInWindow(Component component, int percentOfScreen) { if (percentOfScreen < 0) { centerComponentInWindow(component, -percentOfScreen); return; } if (percentOfScreen > 100) { centerComponentInWindow(component, 100); return; } double percent = percentOfScreen / 100.d; Rectangle bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds(); component.setSize((int) (bounds.getWidth() * percent), (int) (bounds.getHeight() * percent)); centerComponentInWindow(component); }
/** * @return {@link JDialog} Help window and initializes it if necessary */ private static JDialog initHelpWindow() { if (helpWindow == null) { helpWindow = new EscapeDialog(new Frame(),// independent frame to // allow it to be overlaid // by the main frame JMeterUtils.getResString("help"),//$NON-NLS-1$ false); helpWindow.getContentPane().setLayout(new GridLayout(1, 1)); helpWindow.getContentPane().removeAll(); helpWindow.getContentPane().add(scroller); ComponentUtil.centerComponentInWindow(helpWindow, 60); } return helpWindow; }
ComponentUtil.centerComponentInWindow(this);
private void init() { // WARNING: called from ctor so must not be overridden (i.e. must be private or final) templateList.setValues(TemplateManager.getInstance().getTemplateNames()); templateList.addChangeListener(this); reloadTemplateButton.addActionListener(this); reloadTemplateButton.setFont(FONT_SMALL); this.getContentPane().setLayout(new BorderLayout(10, 0)); JPanel templateBar = new JPanel(new BorderLayout()); templateBar.add(templateList, BorderLayout.CENTER); JPanel reloadBtnBar = new JPanel(); reloadBtnBar.add(reloadTemplateButton); templateBar.add(reloadBtnBar, BorderLayout.EAST); this.getContentPane().add(templateBar, BorderLayout.NORTH); helpDoc.setContentType("text/html"); //$NON-NLS-1$ helpDoc.setEditable(false); helpDoc.addHyperlinkListener(this); this.getContentPane().add(scroller, BorderLayout.CENTER); applyTemplateButton.addActionListener(this); cancelButton.addActionListener(this); // Bottom buttons bar JPanel actionBtnBar = new JPanel(new FlowLayout()); actionBtnBar.add(applyTemplateButton); actionBtnBar.add(cancelButton); this.getContentPane().add(actionBtnBar, BorderLayout.SOUTH); this.pack(); this.setMinimumSize(new Dimension(MINIMAL_BOX_WIDTH, MINIMAL_BOX_HEIGHT)); ComponentUtil.centerComponentInWindow(this, 50); // center position and 50% of screen size populateTemplatePage(); }
ComponentUtil.centerComponentInWindow(this);
ComponentUtil.centerComponentInWindow(this);
MainFrame main = new MainFrame(treeModel, treeLis); splash.setProgress(100); ComponentUtil.centerComponentInWindow(main, 80); main.setLocationRelativeTo(splash); main.setVisible(true);