当前位置: 首页>>代码示例>>Java>>正文


Java Window.setLocationRelativeTo方法代码示例

本文整理汇总了Java中java.awt.Window.setLocationRelativeTo方法的典型用法代码示例。如果您正苦于以下问题:Java Window.setLocationRelativeTo方法的具体用法?Java Window.setLocationRelativeTo怎么用?Java Window.setLocationRelativeTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Window的用法示例。


在下文中一共展示了Window.setLocationRelativeTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.awt.Window; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
    final Window window = new BackgroundIsNotUpdated(null);
    window.setSize(300, 300);
    window.setLocationRelativeTo(null);
    window.setVisible(true);
    sleep();
    window.setBackground(Color.GREEN);
    sleep();
    final Robot robot = new Robot();
    robot.setAutoDelay(200);
    Point point = window.getLocationOnScreen();
    Color color = robot.getPixelColor(point.x + window.getWidth() / 2,
                                      point.y + window.getHeight() / 2);
    window.dispose();
    if (!color.equals(Color.GREEN)) {
        throw new RuntimeException(
                "Expected: " + Color.GREEN + " , Actual: " + color);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:BackgroundIsNotUpdated.java

示例2: main

import java.awt.Window; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
    final boolean dump = Boolean.parseBoolean(args[0]);
    final Window w = new Frame() {
        @Override
        public void list(final PrintStream out, final int indent) {
            super.list(out, indent);
            dumped = true;
        }
    };
    w.setSize(200, 200);
    w.setLocationRelativeTo(null);
    w.setVisible(true);

    final Robot robot = new Robot();
    robot.setAutoDelay(50);
    robot.setAutoWaitForIdle(true);
    robot.mouseMove(w.getX() + w.getWidth() / 2,
                    w.getY() + w.getHeight() / 2);
    robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_F1);
    robot.keyRelease(KeyEvent.VK_F1);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.keyRelease(KeyEvent.VK_CONTROL);

    w.dispose();
    if (dumped != dump) {
        throw new RuntimeException("Exp:" + dump + ", actual:" + dumped);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:DumpOnKey.java

示例3: repackWindow

import java.awt.Window; //导入方法依赖的package包/类
/**
 * Repacks the window
 */
private void repackWindow() {
    Window window = SwingUtilities.getWindowAncestor(this);
    if (window != null) {
        window.pack();
        window.setLocationRelativeTo(null);
    }
}
 
开发者ID:VISNode,项目名称:VISNode,代码行数:11,代码来源:ExceptionPanel.java

示例4: centreOnScreen

import java.awt.Window; //导入方法依赖的package包/类
public static void centreOnScreen(Window window)
{
	Window owner = window.getOwner();

	// If the window has an owner, use the same graphics configuration so it
	// will
	// open on the same screen. Otherwise, grab the mouse pointer and work
	// from there.
	GraphicsConfiguration gc = owner != null ? owner.getGraphicsConfiguration() : MouseInfo.getPointerInfo()
		.getDevice().getDefaultConfiguration();

	if( gc != null )
	{
		window.setBounds(centre(getUsableScreenBounds(gc), window.getBounds()));
	}
	else
	{
		// Fall-back to letting Java do the work
		window.setLocationRelativeTo(null);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:22,代码来源:ComponentHelper.java

示例5: main

import java.awt.Window; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
    final Window window = new BackgroundIsNotUpdated(null);
    window.setSize(300, 300);
    window.setLocationRelativeTo(null);
    window.setVisible(true);
    window.requestFocus();
    final ExtendedRobot robot = new ExtendedRobot();
    robot.setAutoDelay(200);
    robot.waitForIdle(1000);
    window.setBackground(Color.GREEN);
    robot.waitForIdle(1000);
    Point point = window.getLocationOnScreen();
    Color color = robot.getPixelColor(point.x + window.getWidth() / 2,
                                      point.y + window.getHeight() / 2);
    window.dispose();
    if (!color.equals(Color.GREEN)) {
        throw new RuntimeException(
                "Expected: " + Color.GREEN + " , Actual: " + color);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:BackgroundIsNotUpdated.java

示例6: packAndCenter

import java.awt.Window; //导入方法依赖的package包/类
public static void packAndCenter(final Window win) {
	// pack
	win.pack();
	final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	win.setSize(Math.min(win.getWidth(), screenSize.width), Math.min(win.getHeight(), screenSize.height - 20));
	// Center on screen
	win.setLocationRelativeTo(null);
}
 
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:9,代码来源:SwingUtilities4.java


注:本文中的java.awt.Window.setLocationRelativeTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。