private static void saveWindowPosition(Frame frame) { if (!isWindowPositioningEnabled()) { return; } Point point; try { point = frame.getLocationOnScreen(); } catch (Exception e) { e.printStackTrace(); try { point = frame.getLocation(); } catch (Exception e2) { e2.printStackTrace(); return; } } int x = (int)point.getX(); int y = (int)point.getY(); int w = frame.getWidth(); int h = frame.getHeight(); Utils.setConfigInteger("window.x", x); Utils.setConfigInteger("window.y", y); Utils.setConfigInteger("window.w", w); Utils.setConfigInteger("window.h", h); LOGGER.debug("Saved window position (x=" + x + ", y=" + y + ", w=" + w + ", h=" + h + ")"); }
private boolean isGeneric() { if (_parent == null) { return false; } return (_parent.getWidth() == 1 && _parent.getHeight() == 1); }
private Dimension get getFrameToScreenRatio(Frame aFrame){ Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); return dimension.setSize(aFrame.getWidth()/dimension.getWidth(), aFrame.getHeight()/dimension.getHeight()); }
boolean frameLayoutCompleted() { final Frame frame = JOptionPane.getFrameForComponent(this); final Insets frameInsets = frame.getInsets(); final Component rootPane = frame.getComponent(0); final boolean frameLayoutCompleted = rootPane.getWidth() == frame.getWidth() - frameInsets.left - frameInsets.right && rootPane.getHeight() == frame.getHeight() - frameInsets.top - frameInsets.bottom; return frameLayoutCompleted; }
public void setVisible(boolean visible) { if (visible) { setLocation((int) frame.getLocation().getX() + (frame.getWidth() / 2) - (getWidth() / 2), (int) frame.getLocation().getY() + (frame.getHeight() / 2) - (getHeight() / 2)); } super.setVisible(visible); }
public AboutFrame(Frame parent) { super(parent, Messages.getString("Viz.About", "Ontopia Vizigator"), true); JPanel mainPanel = new JPanel(); mainPanel.setBackground(Color.white); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.add(createImagePanel()); mainPanel.add(createAboutTextPanel()); this.getContentPane().add(mainPanel); this.pack(); this.setResizable(false); // Center the dialog box above its parent this.setLocation( (parent.getX() + (parent.getWidth() - this.getWidth()) / 2), parent .getY() + (parent.getHeight() - this.getHeight()) / 2); }
/** Center on the specified frame. */ public static void centerOnFrame(Window window, Frame frame) { int ww = window.getWidth(); int wh = window.getHeight(); int fw = frame.getWidth(); int fh = frame.getHeight(); int x = (int)Math.round((double)(fw - ww) / 2); int y = (int)Math.round((double)(fh - wh) / 2); Point location = frame.getLocationOnScreen(); location.translate(x, y); window.setLocation(location); ensureOnScreen(window); }
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;
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;
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); }
@Test public void checkBug53BadLayoutSample1() throws Exception { checkExample(Bug53BadLayoutSample1.class); frame().resizeWidthTo(frame().component().getWidth() + 100); checkSnapshot("after-resize"); }
@Test public void checkBug53BadLayoutWithLeftAndRightInBarRow() throws Exception { checkExample(Bug53BadLayoutWithLeftAndRightInBarRow.class); frame().resizeWidthTo(frame().component().getWidth() + 100); checkSnapshot("after-resize"); }
@Test(enabled = false) public void checkBug53BadLayoutSample2() throws Exception { checkExample(Bug53BadLayoutSample2.class); frame().resizeWidthTo(frame().component().getWidth() + 100); checkSnapshot("after-resize"); }
@Test public void checkSpanRowsOnCustomComponent() throws Exception { launchGui(RowSpan7SpecialComponent.class); checkSnapshot("pref-size"); frame().moveTo(new Point(frame().target.getX(), 0)); Dimension size = new Dimension( frame().target.getWidth(), frame().target.getHeight()); for (int i = 1; i <= 5; i++) { size.width += 6; size.height += 9; frame().resizeTo(size); checkSnapshot("resize-" + i); } }
@Test public void checkBug32ProblemWithJTextPane() throws Exception { // First problem: bad initial baseline checkExample(Bug32ProblemWithJTextPane.class); // Second problem: very bad baseline after appending a lot of text frame().button("append").click(); frame().resizeWidthTo(frame().component().getWidth() + 1); checkSnapshot("after-append"); }
final protected void checkExampleAndResizeWidth( Class<? extends IExample> clazz, double... ratios) throws Exception { launchGui(clazz); checkSnapshot("pref-size"); frame().moveTo(new Point(0, frame().target.getY())); for (int i = 0; i < ratios.length; i++) { frame().resizeWidthTo((int) (frame().target.getWidth() * ratios[i])); checkSnapshot("resize-" + (i + 1)); } }