Java Code Examples for java.awt.Window#getWidth()

The following examples show how to use java.awt.Window#getWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Util.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
/** Centers the specified window on the screen. */
public static void center(final Window w) {
  final Dimension screenSize = getScreenSize(w);
  final int screenWidth = screenSize.width;
  final int screenHeight = screenSize.height;
  final int windowWidth = w.getWidth();
  final int windowHeight = w.getHeight();
  if (windowHeight > screenHeight) {
    return;
  }
  if (windowWidth > screenWidth) {
    return;
  }
  final int x = (screenWidth - windowWidth) / 2;
  final int y = (screenHeight - windowHeight) / 2;
  w.setLocation(x, y);
}
 
Example 2
Source File: HelpButton.java    From thunderstorm with GNU General Public License v3.0 6 votes vote down vote up
/**
 * shows the url in the static window, sizes and positions the window
 * accordingly
 */
private void showInTextWindow() throws IOException {
    window.setVisible(false);
    // same height as parent window of the button, positioned next to it on left or right side
    Window ancestor = SwingUtilities.getWindowAncestor(this);
    window.setPreferredSize(new Dimension(WINDOW_WIDTH, Math.max(ancestor.getHeight(), WINDOW_HEIGHT)));
    int screenEnd = ancestor.getGraphicsConfiguration().getBounds().width + ancestor.getGraphicsConfiguration().getBounds().x;
    Point ancestorLocation = ancestor.getLocationOnScreen();
    if(ancestorLocation.x + ancestor.getWidth() + window.getPreferredSize().width < screenEnd) {
        window.setLocation(ancestorLocation.x + ancestor.getWidth(), ancestorLocation.y);
    } else {
        window.setLocation(ancestorLocation.x - window.getPreferredSize().width, ancestorLocation.y);
    }

    //set page shown in browser
    if(url != null && !url.equals(htmlBrowser.getPage())) {
        try {
            htmlBrowser.setPage(url);
        } catch(Exception e) {
            htmlBrowser.setText("Could not load help file");
        }
    }

    window.pack();
    window.setVisible(true);
}
 
Example 3
Source File: BubbleWindow.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * method to get to know whether the AbstractButton with the given key is on Screen
 *
 * @param dockableKey
 *            i18nKey of the wanted AbstractButton
 * @return returns 0 if the AbstractButton is on the Screen, 1 if the AbstractButton is on
 *         Screen but the user can not see it with the current settings of the perspective and
 *         -1 if the AbstractButton is not on the Screen.
 */
public static int isButtonOnScreen(final String buttonKey) {
	// find the Button and return -1 if we can not find it
	Component onScreen;
	try {
		onScreen = BubbleWindow.findButton(buttonKey, RapidMinerGUI.getMainFrame());
	} catch (NullPointerException e) {
		return OBJECT_NOT_ON_SCREEN;
	}
	if (onScreen == null) {
		return OBJECT_NOT_ON_SCREEN;
	}
	// detect whether the Button is viewable
	int xposition = onScreen.getLocationOnScreen().x;
	int yposition = onScreen.getLocationOnScreen().y;
	int otherXposition = xposition + onScreen.getWidth();
	int otherYposition = yposition + onScreen.getHeight();
	Window frame = RapidMinerGUI.getMainFrame();
	if (otherXposition <= frame.getWidth() && otherYposition <= frame.getHeight() && xposition > 0 && yposition > 0) {
		return OBJECT_SHOWING_ON_SCREEN;
	} else {
		return OBJECT_NOT_SHOWING;
	}
}
 
Example 4
Source File: FullScreenInsets.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testWindowBounds(final DisplayMode dm, final Window w) {
    if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {
        System.err.println(" Wrong window bounds:" +
                           " Expected: width = " + dm.getWidth()
                           + ", height = " + dm.getHeight() + " Actual: "
                           + w.getSize());
        passed = false;
    }
}
 
Example 5
Source File: WindowMouseHandler.java    From littleluck with Apache License 2.0 5 votes vote down vote up
/**
 *  v1.0.1:修复自定义拖拽区域BUG, 保存游标状态
 */
public void mouseMoved(MouseEvent e)
{
    Window window = (Window)e.getSource();

    int w = window.getWidth();

    int h = window.getHeight();

    Point point = e.getPoint();

    JRootPane rootPane = LuckWindowUtil.getRootPane(window);

    int cursor = 0;

    if(rootPane != null && LuckWindowUtil.isResizable(window))
    {
        cursor = getCursor(w, h, point, rootPane.getInsets());
    }

    if(cursor != Cursor.DEFAULT_CURSOR)
    {
        window.setCursor(Cursor.getPredefinedCursor(cursor));
    }
    else
    {
        window.setCursor(lastCursor);
    }
    
    dragCursor = cursor;
}
 
Example 6
Source File: PFrame.java    From PolyGlot with MIT License 5 votes vote down vote up
/**
 * Sets window visibly to the right of the window handed in
 *
 * @param w window to set location relative to
 */
public void setBeside(final Window w) {
    int x = w.getLocation().x + w.getWidth();
    int y = w.getLocation().y;

    setLocation(x, y);
    ignoreCenter = true;
}
 
Example 7
Source File: FullScreenInsets.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testWindowBounds(final DisplayMode dm, final Window w) {
    if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {
        System.err.println(" Wrong window bounds:" +
                           " Expected: width = " + dm.getWidth()
                           + ", height = " + dm.getHeight() + " Actual: "
                           + w.getSize());
        passed = false;
    }
}
 
Example 8
Source File: FullScreenInsets.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testWindowBounds(final DisplayMode dm, final Window w) {
    if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {
        System.err.println(" Wrong window bounds:" +
                           " Expected: width = " + dm.getWidth()
                           + ", height = " + dm.getHeight() + " Actual: "
                           + w.getSize());
        passed = false;
    }
}
 
Example 9
Source File: FullScreenInsets.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testWindowBounds(final DisplayMode dm, final Window w) {
    if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {
        System.err.println(" Wrong window bounds:" +
                           " Expected: width = " + dm.getWidth()
                           + ", height = " + dm.getHeight() + " Actual: "
                           + w.getSize());
        passed = false;
    }
}
 
Example 10
Source File: FullScreenInsets.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testWindowBounds(final DisplayMode dm, final Window w) {
    if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {
        System.err.println(" Wrong window bounds:" +
                           " Expected: width = " + dm.getWidth()
                           + ", height = " + dm.getHeight() + " Actual: "
                           + w.getSize());
        passed = false;
    }
}
 
Example 11
Source File: FullScreenInsets.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void testWindowBounds(final DisplayMode dm, final Window w) {
    if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {
        System.err.println(" Wrong window bounds:" +
                           " Expected: width = " + dm.getWidth()
                           + ", height = " + dm.getHeight() + " Actual: "
                           + w.getSize());
        passed = false;
    }
}
 
Example 12
Source File: FullScreenInsets.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testWindowBounds(final DisplayMode dm, final Window w) {
    if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {
        System.err.println(" Wrong window bounds:" +
                           " Expected: width = " + dm.getWidth()
                           + ", height = " + dm.getHeight() + " Actual: "
                           + w.getSize());
        passed = false;
    }
}
 
Example 13
Source File: MouseWheelAbsXY.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(GraphicsConfiguration gc) throws AWTException {
    final Window frame = new Frame(gc);
    try {
        frame.addMouseWheelListener(e -> {
            wheelX = e.getXOnScreen();
            wheelY = e.getYOnScreen();
            done = true;
        });
        frame.setSize(300, 300);
        frame.setVisible(true);

        final Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.setAutoWaitForIdle(true);
        mouseX = frame.getX() + frame.getWidth() / 2;
        mouseY = frame.getY() + frame.getHeight() / 2;

        robot.mouseMove(mouseX, mouseY);
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseWheel(10);

        validate();
    } finally {
        frame.dispose();
    }
}
 
Example 14
Source File: FullScreenInsets.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testWindowBounds(final DisplayMode dm, final Window w) {
    if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {
        System.err.println(" Wrong window bounds:" +
                           " Expected: width = " + dm.getWidth()
                           + ", height = " + dm.getHeight() + " Actual: "
                           + w.getSize());
        passed = false;
    }
}
 
Example 15
Source File: FullScreenInsets.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void testWindowBounds(final DisplayMode dm, final Window w) {
    if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {
        System.err.println(" Wrong window bounds:" +
                           " Expected: width = " + dm.getWidth()
                           + ", height = " + dm.getHeight() + " Actual: "
                           + w.getSize());
        passed = false;
    }
}
 
Example 16
Source File: FullScreenInsets.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void testWindowBounds(final DisplayMode dm, final Window w) {
    if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {
        System.err.println(" Wrong window bounds:" +
                           " Expected: width = " + dm.getWidth()
                           + ", height = " + dm.getHeight() + " Actual: "
                           + w.getSize());
        passed = false;
    }
}
 
Example 17
Source File: PDialog.java    From PolyGlot with MIT License 5 votes vote down vote up
/**
 * Sets window visibly to the right of the window handed in
 *
 * @param w window to set location relative to
 */
public void setBeside(final Window w) {
    final Window self = this;
    skipCenter = true;
    
    int x = w.getLocation().x + w.getWidth();
    int y = w.getLocation().y;

    self.setLocation(x, y);
}
 
Example 18
Source File: FullScreenInsets.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testWindowBounds(final DisplayMode dm, final Window w) {
    if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {
        System.err.println(" Wrong window bounds:" +
                           " Expected: width = " + dm.getWidth()
                           + ", height = " + dm.getHeight() + " Actual: "
                           + w.getSize());
        passed = false;
    }
}
 
Example 19
Source File: BETitlePane.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
/**
	 * Renders the TitlePane.
	 *
	 * @param g the g
	 */
	public void paintComponent(Graphics g)
	{
		// As state isn't bound, we need a convenience place to check
		// if it has changed. Changing the state typically changes the
		if (getFrame() != null)
		{
			setState(getFrame().getExtendedState());
		}
		JRootPane rootPane = getRootPane();
		Window window = getWindow();
		boolean leftToRight = (window == null) ? rootPane
				.getComponentOrientation().isLeftToRight() : window
				.getComponentOrientation().isLeftToRight();
		boolean isSelected = (window == null) ? true : window.isActive();
		int width = getWidth();
		int height = getHeight();

		Color background;
		Color foreground;
		Color darkShadow;

		if (isSelected)
		{
			background = activeBackground;
			foreground = activeForeground;
			darkShadow = activeShadow;
		}
		else
		{
			background = inactiveBackground;
			foreground = inactiveForeground;
			darkShadow = inactiveShadow;
//			bumps = inactiveBumps;
		}
		//----------------------------------------------- 标题背景
		paintTitlePane(g,0,0,width,height,isSelected);

		//----------------------------------------------- 标题文字和图片
		int xOffset = leftToRight ? 5 : width - 5;

		if (getWindowDecorationStyle() == JRootPane.FRAME||getWindowDecorationStyle() ==JRootPane.PLAIN_DIALOG)
		{
			xOffset += leftToRight ? IMAGE_WIDTH + 5 : -IMAGE_WIDTH - 5;
		}

		String theTitle = getTitle();
		if (theTitle != null)
		{
			FontMetrics fm = MySwingUtilities2.getFontMetrics(rootPane, g);
			int yOffset = ((height - fm.getHeight()) / 2) + fm.getAscent();

			Rectangle rect = new Rectangle(0, 0, 0, 0);
			if (iconifyButton != null && iconifyButton.getParent() != null)
			{
				rect = iconifyButton.getBounds();
			}
			int titleW;

			if (leftToRight)
			{
				if (rect.x == 0)
				{
					rect.x = window.getWidth() - window.getInsets().right - 2;
				}
				titleW = rect.x - xOffset - 4;
				theTitle = MySwingUtilities2.clipStringIfNecessary(rootPane, fm,
						theTitle, titleW);
			}
			else
			{
				titleW = xOffset - rect.x - rect.width - 4;
				theTitle = MySwingUtilities2.clipStringIfNecessary(rootPane, fm,
						theTitle, titleW);
				xOffset -= MySwingUtilities2.stringWidth(rootPane, fm, theTitle);
			}
			
			int titleLength = MySwingUtilities2.stringWidth(rootPane, fm,theTitle);
			g.setColor(foreground);
			MySwingUtilities2.drawString(rootPane, g, theTitle, xOffset, yOffset);
			xOffset += leftToRight ? titleLength + 5 : -5;
		}
	}
 
Example 20
Source File: WindowChoreographer.java    From rapidminer-studio with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Check if there is enough space for the Window
 *
 * @param w
 *            The window to insert
 * @param yOffset
 *            The start offset of the Window
 * @return true if it fits on the screen
 */
private boolean fitsScreen(Window w, int yOffset) {
	return yOffset + w.getHeight() <= parent.getHeight() && parent.getWidth() >= w.getWidth() + DEFAULT_RIGHT_MARGIN;
}