Java Code Examples for java.awt.Toolkit#getScreenSize()

The following examples show how to use java.awt.Toolkit#getScreenSize() . 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: GuiHelper.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * Centers the child component relative to it's parent component
 * 
 * @param parent
 * @param child
 * @param bStayOnScreen
 */
public static final void centerChildToParent(final Component parent, final Component child,
    final boolean bStayOnScreen) {
  int x = (parent.getX() + (parent.getWidth() / 2)) - (child.getWidth() / 2);
  int y = (parent.getY() + (parent.getHeight() / 2)) - (child.getHeight() / 2);
  if (bStayOnScreen) {
    final Toolkit tk = Toolkit.getDefaultToolkit();
    final Dimension ss = new Dimension(tk.getScreenSize());
    if ((x + child.getWidth()) > ss.getWidth()) {
      x = (int) (ss.getWidth() - child.getWidth());
    }
    if ((y + child.getHeight()) > ss.getHeight()) {
      y = (int) (ss.getHeight() - child.getHeight());
    }
    if (x < 0) {
      x = 0;
    }
    if (y < 0) {
      y = 0;
    }
  }
  child.setLocation(x, y);
}
 
Example 2
Source File: bug8071705.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) {

        GraphicsDevice correctDevice = null;
        if (devices.length < 2) {
            return correctDevice;
        }

        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
        int halfScreen = screenBounds.height/2;

        for(int i = 0; i < devices.length; i++) {
            if(devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
                GraphicsConfiguration conf =
                        devices[i].getDefaultConfiguration();
                Rectangle bounds = conf.getBounds();
                if (bounds.y >= halfScreen) {
                    // found
                    correctDevice = devices[i];
                    break;
                }
            }
        }
        return correctDevice;
    }
 
Example 3
Source File: bug8071705.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) {

        GraphicsDevice correctDevice = null;
        if (devices.length < 2) {
            return correctDevice;
        }

        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
        int halfScreen = screenBounds.height/2;

        for(int i = 0; i < devices.length; i++) {
            if(devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
                GraphicsConfiguration conf =
                        devices[i].getDefaultConfiguration();
                Rectangle bounds = conf.getBounds();
                if (bounds.y >= halfScreen) {
                    // found
                    correctDevice = devices[i];
                    break;
                }
            }
        }
        return correctDevice;
    }
 
Example 4
Source File: bug8071705.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) {

        GraphicsDevice correctDevice = null;
        if (devices.length < 2) {
            return correctDevice;
        }

        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
        int halfScreen = screenBounds.height/2;

        for(int i = 0; i < devices.length; i++) {
            if(devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
                GraphicsConfiguration conf =
                        devices[i].getDefaultConfiguration();
                Rectangle bounds = conf.getBounds();
                if (bounds.y >= halfScreen) {
                    // found
                    correctDevice = devices[i];
                    break;
                }
            }
        }
        return correctDevice;
    }
 
Example 5
Source File: bug8071705.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) {

        GraphicsDevice correctDevice = null;
        if (devices.length < 2) {
            return correctDevice;
        }

        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
        int halfScreen = screenBounds.height/2;

        for(int i = 0; i < devices.length; i++) {
            if(devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
                GraphicsConfiguration conf =
                        devices[i].getDefaultConfiguration();
                Rectangle bounds = conf.getBounds();
                if (bounds.y >= halfScreen) {
                    // found
                    correctDevice = devices[i];
                    break;
                }
            }
        }
        return correctDevice;
    }
 
Example 6
Source File: DialogEditor.java    From ET_Redux with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param preferredWidth
 * @param myPreferredHeight
 */
protected void setSizeAndCenter(int preferredWidth, int myPreferredHeight) {
    int preferredHeight = myPreferredHeight;
    preferredHeight += (BrowserControl.isMacOS() ? 0 : 25);
    super.setSize(preferredWidth, preferredHeight);
    super.setPreferredSize(new Dimension(preferredWidth, preferredHeight));

    //Get the screen size
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screenSize = toolkit.getScreenSize();

    //Calculate the frame location
    int x = (screenSize.width - getWidth()) / 2;
    int y = (screenSize.height - getHeight()) / 2;

    //Set the new frame location centered
    setLocation(x, y);
}
 
Example 7
Source File: NowPlayingNotification.java    From aurous-app with GNU General Public License v2.0 6 votes vote down vote up
public void displayAlert() throws InterruptedException {

		final Toolkit aToolkit = Toolkit.getDefaultToolkit();
		final Dimension screen = aToolkit.getScreenSize();
		final int xPosition = screen.width - (this.WIDTH); // Right edge of the
		// screen
		for (int i = 0; i < this.HEIGHT_ADD; i++) {

			final int yPosition = screen.height - (this.HEIGHT + i); // Bottom
			// edge
			// of
			// the
			// screen
			setBounds(xPosition, yPosition, this.WIDTH, this.HEIGHT);
			Thread.sleep(10);

		}
		Thread.sleep(3000);
		removeAlert();

	}
 
Example 8
Source File: bug8071705.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) {

        GraphicsDevice correctDevice = null;
        if (devices.length < 2) {
            return correctDevice;
        }

        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
        int halfScreen = screenBounds.height/2;

        for(int i = 0; i < devices.length; i++) {
            if(devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
                GraphicsConfiguration conf =
                        devices[i].getDefaultConfiguration();
                Rectangle bounds = conf.getBounds();
                if (bounds.y >= halfScreen) {
                    // found
                    correctDevice = devices[i];
                    break;
                }
            }
        }
        return correctDevice;
    }
 
Example 9
Source File: bug8071705.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) {

        GraphicsDevice correctDevice = null;
        if (devices.length < 2) {
            return correctDevice;
        }

        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
        int halfScreen = screenBounds.height/2;

        for(int i = 0; i < devices.length; i++) {
            if(devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
                GraphicsConfiguration conf =
                        devices[i].getDefaultConfiguration();
                Rectangle bounds = conf.getBounds();
                if (bounds.y >= halfScreen) {
                    // found
                    correctDevice = devices[i];
                    break;
                }
            }
        }
        return correctDevice;
    }
 
Example 10
Source File: DialogEditor.java    From ET_Redux with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param width
 * @param height
 */
@Override
public void setSize(int width, int height) {
    if (BrowserControl.isMacOS()) {
        super.setSize(width, height);
    }
    if (BrowserControl.isWindowsPlatform()) {
        super.setSize(width, height + 25);
    }

    //Get the screen size
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screenSize = toolkit.getScreenSize();

    //Calculate the frame location
    int x = (screenSize.width - getWidth()) / 2;
    int y = (screenSize.height - getHeight()) / 2;

    //Set the new frame location
    setLocation(x, y);
}
 
Example 11
Source File: FrameUtil.java    From JAVA-MVC-Swing-Monopoly with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * frame������
 * 
 * @param jf
 */
public static void setFrameCenter (JFrame jf) {
	Toolkit toolkit = Toolkit.getDefaultToolkit();
	Dimension screen = toolkit.getScreenSize();// �����ݶ���
	int x = (screen.width - jf.getWidth()) / 2;
	int y = (screen.height - jf.getHeight()) / 2 - 32;
	jf.setLocation(x, y);
}
 
Example 12
Source File: MaximizedToMaximized.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

       Frame frame = new Frame();
        final Toolkit toolkit = Toolkit.getDefaultToolkit();
        final GraphicsEnvironment graphicsEnvironment =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
        final GraphicsDevice graphicsDevice =
                graphicsEnvironment.getDefaultScreenDevice();

        final Dimension screenSize = toolkit.getScreenSize();
        final Insets screenInsets = toolkit.getScreenInsets(
                graphicsDevice.getDefaultConfiguration());

        final Rectangle availableScreenBounds = new Rectangle(screenSize);

        availableScreenBounds.x += screenInsets.left;
        availableScreenBounds.y += screenInsets.top;
        availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
        availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);

        frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
                availableScreenBounds.width, availableScreenBounds.height);
        frame.setVisible(true);

        Rectangle frameBounds = frame.getBounds();
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
        ((SunToolkit) toolkit).realSync();

        Rectangle maximizedFrameBounds = frame.getBounds();
        if (maximizedFrameBounds.width < frameBounds.width
                || maximizedFrameBounds.height < frameBounds.height) {
            throw new RuntimeException("Maximized frame is smaller than non maximized");
        }
    }
 
Example 13
Source File: QFixMessengerFrame.java    From quickfix-messenger with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void positionFrame()
{
	Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
	Dimension screenSize = defaultToolkit.getScreenSize();
	int screenHeight = screenSize.height;
	int screenWidth = screenSize.width;
	setSize(screenWidth / 2, screenHeight / 2);
	setLocation(screenWidth / 4, screenHeight / 4);
}
 
Example 14
Source File: UIUtil.java    From rest-client with Apache License 2.0 5 votes vote down vote up
/**
* 
* @Title: setLocation 
* @Description: set component's location
* @param @param c 
* @return void
* @throws
 */
public static void setLocation(Component c)
{
    int winWidth = c.getWidth();
    int winHeight = c.getHeight();

    Toolkit kit = Toolkit.getDefaultToolkit();
    Dimension screenSize = kit.getScreenSize();

    int screenWidth = screenSize.width;
    int screenHeight = screenSize.height;

    c.setLocation(screenWidth / 2 - winWidth / 2, screenHeight / 2 - winHeight / 2);
}
 
Example 15
Source File: LoginFrame.java    From xyTalk-pc with GNU Affero General Public License v3.0 5 votes vote down vote up
private void initView() {
	JPanel contentPanel = new JPanel();
	contentPanel.setBorder(new LineBorder(Colors.LIGHT_GRAY));
	contentPanel.setLayout(new GridBagLayout());

	controlPanel.add(closeLabel);

	if (OSUtil.getOsType() != OSUtil.Mac_OS) {
		setUndecorated(true);
		contentPanel.add(controlPanel, new GBC(0, 0).setFill(GBC.BOTH).setWeight(1, 1).setInsets(5, 0, 0, 0));
	}

	JPanel titlePanel = new JPanel();
	titlePanel.add(titleLabel);

	JPanel buttonPanel = new JPanel();
	buttonPanel.setLayout(new GridBagLayout());
	//buttonPanel.add(loginButton, new GBC(0, 0).setFill(GBC.HORIZONTAL).setWeight(2, 1).setInsets(10, 0, 0, 0));		
	buttonPanel.add(remberPsw, new GBC(0, 1).setFill(GBC.HORIZONTAL).setWeight(1, 1).setInsets(20, 10, 0, 0));
	buttonPanel.add(downloadLabel, new GBC(1, 1).setFill(GBC.HORIZONTAL).setWeight(1, 1).setInsets(20, 10, 0, 0));
	buttonPanel.add(offlineLogin, new GBC(0, 2).setFill(GBC.HORIZONTAL).setWeight(1, 1).setInsets(20, 10, 0, 0));		
	
	editPanel.add(usernameField);
	editPanel.add(passwordField);
	editPanel.add(loginButton);
	editPanel.add(buttonPanel);
	editPanel.add(statusLabel);
	add(contentPanel);
	contentPanel.add(titlePanel, new GBC(0, 1).setFill(GBC.BOTH).setWeight(2, 1).setInsets(10, 10, 0, 10));
	contentPanel.add(editPanel, new GBC(0, 2).setFill(GBC.BOTH).setWeight(2, 10).setInsets(10, 10, 0, 10));

       Toolkit tk = Toolkit.getDefaultToolkit();
       Launcher.currentWindowWidth = tk.getScreenSize().width;
       Launcher.currentWindowHeight = tk.getScreenSize().height;
}
 
Example 16
Source File: BaseEvent.java    From HBaseClient with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 屏幕中间显示对话窗口
 * 
 * @param i_JDialog
 */
public void showCreate(JDialog i_JDialog)
{
    Toolkit v_Toolkit = Toolkit.getDefaultToolkit(); 
    int     v_X       = (v_Toolkit.getScreenSize().height - i_JDialog.getHeight()) / 2;
    int     v_Y       = (v_Toolkit.getScreenSize().width  - i_JDialog.getWidth() ) / 2;
    
    i_JDialog.setLocation(v_Y ,v_X);
    i_JDialog.setVisible(true);
}
 
Example 17
Source File: WinCenter.java    From Java with Artistic License 2.0 5 votes vote down vote up
public static void center(Window win){
	Toolkit tkit = Toolkit.getDefaultToolkit();
	Dimension sSize = tkit.getScreenSize();
	Dimension wSize = win.getSize();
	if(wSize.height > sSize.height){
		wSize.height = sSize.height;
	}
	if(wSize.width > sSize.width){
		wSize.width = sSize.width;
	}
	win.setLocation((sSize.width - wSize.width)/ 2, (sSize.height - wSize.height)/ 2);
}
 
Example 18
Source File: MaximizedToMaximized.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

       Frame frame = new Frame();
        final Toolkit toolkit = Toolkit.getDefaultToolkit();
        final GraphicsEnvironment graphicsEnvironment =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
        final GraphicsDevice graphicsDevice =
                graphicsEnvironment.getDefaultScreenDevice();

        final Dimension screenSize = toolkit.getScreenSize();
        final Insets screenInsets = toolkit.getScreenInsets(
                graphicsDevice.getDefaultConfiguration());

        final Rectangle availableScreenBounds = new Rectangle(screenSize);

        availableScreenBounds.x += screenInsets.left;
        availableScreenBounds.y += screenInsets.top;
        availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
        availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);

        frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
                availableScreenBounds.width, availableScreenBounds.height);
        frame.setVisible(true);

        Rectangle frameBounds = frame.getBounds();
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
        ((SunToolkit) toolkit).realSync();

        Rectangle maximizedFrameBounds = frame.getBounds();
        if (maximizedFrameBounds.width < frameBounds.width
                || maximizedFrameBounds.height < frameBounds.height) {
            throw new RuntimeException("Maximized frame is smaller than non maximized");
        }
    }
 
Example 19
Source File: MaximizedToMaximized.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

       Frame frame = new Frame();
        final Toolkit toolkit = Toolkit.getDefaultToolkit();
        final GraphicsEnvironment graphicsEnvironment =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
        final GraphicsDevice graphicsDevice =
                graphicsEnvironment.getDefaultScreenDevice();

        final Dimension screenSize = toolkit.getScreenSize();
        final Insets screenInsets = toolkit.getScreenInsets(
                graphicsDevice.getDefaultConfiguration());

        final Rectangle availableScreenBounds = new Rectangle(screenSize);

        availableScreenBounds.x += screenInsets.left;
        availableScreenBounds.y += screenInsets.top;
        availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
        availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);

        frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
                availableScreenBounds.width, availableScreenBounds.height);
        frame.setVisible(true);

        Rectangle frameBounds = frame.getBounds();
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
        ((SunToolkit) toolkit).realSync();

        Rectangle maximizedFrameBounds = frame.getBounds();
        if (maximizedFrameBounds.width < frameBounds.width
                || maximizedFrameBounds.height < frameBounds.height) {
            throw new RuntimeException("Maximized frame is smaller than non maximized");
        }
    }
 
Example 20
Source File: Query.java    From opt4j with MIT License 4 votes vote down vote up
/**
 * Add a label and a widget to the panel.
 * 
 * @param name
 *            The name of the entry.
 * @param label
 *            The label.
 * @param widget
 *            The interactive entry to the right of the label.
 * @param entry
 *            The object that contains user data.
 */
protected void _addPair(String name, JLabel label, Component widget, Object entry) {
	// Surely there is a better layout manager in swing...
	// Note that Box and BoxLayout do not work because they do not
	// support gridded layout.
	_constraints.gridwidth = 1;
	_constraints.insets = _leftPadding;
	_grid.setConstraints(label, _constraints);
	_entryPanel.add(label);

	_constraints.insets = _noPadding;

	if ((_columns > 1) && (((_entries.size() + 1) % _columns) != 0)) {
		_constraints.gridwidth = 1;
	} else {
		_constraints.gridwidth = GridBagConstraints.REMAINDER;
	}

	_grid.setConstraints(widget, _constraints);
	_entryPanel.add(widget);

	_entries.put(name, entry);
	_labels.put(name, label);
	_previous.put(name, getStringValue(name));

	Dimension preferredSize = _entryPanel.getPreferredSize();

	// Add some slop to the width to take in to account
	// the width of the vertical scrollbar.
	preferredSize.width += 25;

	// Applets seem to need this, see CT/SigmaDelta
	_widgetsHeight += widget.getPreferredSize().height;
	preferredSize.height = _widgetsHeight;

	Toolkit tk = Toolkit.getDefaultToolkit();

	if (preferredSize.height > tk.getScreenSize().height) {
		// Fudge factor to keep this window smaller than the screen
		// height. CGSUnitBase and the Code Generator are good tests.
		preferredSize.height = (int) (tk.getScreenSize().height * 0.75);
		_entryScrollPane.setPreferredSize(preferredSize);
	}

	_entryScrollPane.setPreferredSize(preferredSize);

	// Call revalidate for the scrollbar.
	_entryPanel.revalidate();
}