本文整理匯總了Java中java.awt.GraphicsConfiguration.getBounds方法的典型用法代碼示例。如果您正苦於以下問題:Java GraphicsConfiguration.getBounds方法的具體用法?Java GraphicsConfiguration.getBounds怎麽用?Java GraphicsConfiguration.getBounds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.GraphicsConfiguration
的用法示例。
在下文中一共展示了GraphicsConfiguration.getBounds方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkConfigs
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
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;
}
示例2: show
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
public void show(Point location) {
Rectangle screenBounds = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
for (GraphicsDevice device : gds) {
GraphicsConfiguration gc = device.getDefaultConfiguration();
screenBounds = gc.getBounds();
if (screenBounds.contains(location)) {
break;
}
}
// showing the popup tooltip
cp = new TooltipContentPanel(master.getTextComponent());
Window w = SwingUtilities.windowForComponent(master.getTextComponent());
contentWindow = new JWindow(w);
contentWindow.add(cp);
contentWindow.pack();
Dimension dim = contentWindow.getSize();
if (location.y + dim.height + SCREEN_BORDER > screenBounds.y + screenBounds.height) {
dim.height = (screenBounds.y + screenBounds.height) - (location.y + SCREEN_BORDER);
}
if (location.x + dim.width + SCREEN_BORDER > screenBounds.x + screenBounds.width) {
dim.width = (screenBounds.x + screenBounds.width) - (location.x + SCREEN_BORDER);
}
contentWindow.setSize(dim);
contentWindow.setLocation(location.x, location.y - 1); // slight visual adjustment
contentWindow.setVisible(true);
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
w.addWindowFocusListener(this);
contentWindow.addWindowFocusListener(this);
}
示例3: initScreenBounds
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
static void initScreenBounds() {
GraphicsDevice[] devices = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getScreenDevices();
screenBounds = new Rectangle[devices.length];
scales = new double[devices.length][2];
for (int i = 0; i < devices.length; i++) {
GraphicsConfiguration gc = devices[i].getDefaultConfiguration();
screenBounds[i] = gc.getBounds();
AffineTransform tx = gc.getDefaultTransform();
scales[i][0] = tx.getScaleX();
scales[i][1] = tx.getScaleY();
}
maxBounds = screenBounds[0];
for (int i = 0; i < screenBounds.length; i++) {
maxBounds = maxBounds.union(screenBounds[i]);
}
}
示例4: initScreenBounds
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
static void initScreenBounds() {
GraphicsDevice[] devices = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getScreenDevices();
screenBounds = new Rectangle[devices.length];
scales = new double[devices.length][2];
for (int i = 0; i < devices.length; i++) {
GraphicsConfiguration gc = devices[i].getDefaultConfiguration();
screenBounds[i] = gc.getBounds();
AffineTransform tx = gc.getDefaultTransform();
scales[i][0] = tx.getScaleX();
scales[i][1] = tx.getScaleY();
}
for (int i = 0; i < devices.length; i++) {
for (int j = i + 1; j < devices.length; j++) {
if (scales[i][0] != scales[j][0] || scales[i][1] != scales[j][1]) {
screen1 = i;
screen2 = j;
}
}
}
}
示例5: getDefaultDisplayMode
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
private DisplayMode getDefaultDisplayMode() {
GraphicsConfiguration gc = getDefaultConfiguration();
Rectangle r = gc.getBounds();
return new DisplayMode(r.width, r.height,
DisplayMode.BIT_DEPTH_MULTI,
DisplayMode.REFRESH_RATE_UNKNOWN);
}
示例6: findCenterBounds
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
/**
* Helps client code place components on the center of the screen. It
* handles multiple monitor configuration correctly
*
* @param gconf the GraphicsConfiguration of the monitor
* @param componentSize the size of the component
* @return bounds of the centered component
*/
private static Rectangle findCenterBounds(GraphicsConfiguration gconf, Dimension componentSize) {
if (gconf == null) {
gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
}
Rectangle bounds = gconf.getBounds();
return new Rectangle(
bounds.x + ((bounds.width - componentSize.width) / 2),
bounds.y + ((bounds.height - componentSize.height) / 2), componentSize.width, componentSize.height
);
}
示例7: main
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
// Windows only test
if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
// Retrieving top edge of Desktop
GraphicsConfiguration grConf = GraphicsEnvironment
.getLocalGraphicsEnvironment().getDefaultScreenDevice()
.getDefaultConfiguration();
Rectangle scrRect = grConf.getBounds();
Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(grConf);
scrTop = scrRect.y + scrInsets.top;
color = new Color(0, 255, 0);
SwingUtilities.invokeAndWait(() -> {
createAndShowUI();
});
try {
Robot robot = new Robot();
robot.setAutoDelay(500);
robot.setAutoWaitForIdle(true);
robot.delay(1000);
// Resizing a window to invoke Windows Snap feature
readFrameInfo();
robot.mouseMove(frLoc.x + frSize.width / 2, frLoc.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseMove(frLoc.x + frSize.width / 2, scrTop);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
// Retrieving the color of window expanded area
readFrameInfo();
Insets insets = frame.getInsets();
Color bgColor = robot.getPixelColor(frLoc.x + frSize.width / 2,
frLoc.y + frSize.height - insets.bottom - 1);
frame.dispose();
if (!bgColor.equals(color)) {
throw new RuntimeException("TEST FAILED: got "
+ bgColor + " instead of " + color);
}
System.out.println("TEST PASSED!");
} catch (AWTException ex) {
throw new RuntimeException("TEST FAILED!");
}
}
}
示例8: getUsableScreenBounds
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
private static Rectangle getUsableScreenBounds(GraphicsConfiguration gconf) {
if (gconf == null) {
gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
}
return new Rectangle(gconf.getBounds());
}
示例9: getScreenBounds
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
private Rectangle getScreenBounds() {
Rectangle res = null;
PointerInfo pi = MouseInfo.getPointerInfo();
if( null != pi ) {
GraphicsDevice gd = pi.getDevice();
if( gd != null ) {
GraphicsConfiguration gc = gd.getDefaultConfiguration();
if( gc != null ) {
res = gc.getBounds();
}
}
}
return res;
}
示例10: getUsableScreenBounds
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
public static Rectangle getUsableScreenBounds(GraphicsConfiguration gc)
{
Rectangle screen = gc.getBounds();
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
screen.x += insets.left;
screen.y += insets.top;
screen.width -= insets.left + insets.right;
screen.height -= insets.top + insets.bottom;
return screen;
}
示例11: getScreenBoundsForPoint
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
/**
* Returns the screen coordinates for the monitor that contains the
* specified point. This is useful for setups with multiple monitors,
* to ensure that popup windows are positioned properly.
*
* @param x The x-coordinate, in screen coordinates.
* @param y The y-coordinate, in screen coordinates.
* @return The bounds of the monitor that contains the specified point.
*/
public static Rectangle getScreenBoundsForPoint(int x, int y) {
GraphicsEnvironment env = GraphicsEnvironment.
getLocalGraphicsEnvironment();
GraphicsDevice[] devices = env.getScreenDevices();
for (int i=0; i<devices.length; i++) {
GraphicsConfiguration config = devices[i].getDefaultConfiguration();
Rectangle gcBounds = config.getBounds();
if (gcBounds.contains(x, y)) {
return gcBounds;
}
}
// If point is outside all monitors, default to default monitor (?)
return env.getMaximumWindowBounds();
}
示例12: getUsableBounds
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
/**
* Return the bounds of a GraphicsDevice, less its screen insets.
* See also java.awt.GraphicsEnvironment.getUsableBounds();
*/
public static Rectangle getUsableBounds(GraphicsDevice gd) {
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
Rectangle usableBounds = gc.getBounds();
usableBounds.x += insets.left;
usableBounds.y += insets.top;
usableBounds.width -= (insets.left + insets.right);
usableBounds.height -= (insets.top + insets.bottom);
return usableBounds;
}
示例13: main
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
public static void main(String[] args) throws AWTException
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (gds.length < 2) {
System.out.println("It's a multiscreen test... skipping!");
return;
}
for (int i = 0; i < gds.length; ++i) {
GraphicsDevice gd = gds[i];
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Rectangle screen = gc.getBounds();
Robot robot = new Robot(gd);
// check Robot.mouseMove()
robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
Point mouse = MouseInfo.getPointerInfo().getLocation();
Point point = screen.getLocation();
point.translate(mouseOffset.x, mouseOffset.y);
if (!point.equals(mouse)) {
throw new RuntimeException(getErrorText("Robot.mouseMove", i));
}
// check Robot.getPixelColor()
Frame frame = new Frame(gc);
frame.setUndecorated(true);
frame.setSize(100, 100);
frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
frame.setBackground(color);
frame.setVisible(true);
robot.waitForIdle();
Rectangle bounds = frame.getBounds();
if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
}
// check Robot.createScreenCapture()
BufferedImage image = robot.createScreenCapture(bounds);
int rgb = color.getRGB();
if (image.getRGB(0, 0) != rgb
|| image.getRGB(image.getWidth() - 1, 0) != rgb
|| image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb
|| image.getRGB(0, image.getHeight() - 1) != rgb) {
throw new RuntimeException(
getErrorText("Robot.createScreenCapture", i));
}
frame.dispose();
}
System.out.println("Test PASSED!");
}
示例14: setLocation
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
private static Rectangle setLocation(JFrame frame, GraphicsDevice device) {
GraphicsConfiguration conf = device.getDefaultConfiguration();
Rectangle bounds = conf.getBounds();
// put just below half screen
int x = bounds.x + bounds.width/2;
int y = bounds.y + bounds.height/2;
frame.setLocation(x, y);
return bounds;
}
示例15: main
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
OSInfo.OSType type = OSInfo.getOSType();
if (type != OSInfo.OSType.LINUX && type != OSInfo.OSType.SOLARIS) {
System.out.println("This test is for Solaris and Linux only..." +
"skipping!");
return;
}
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (gds.length < 2) {
System.out.println("It's a multi-screen test... skipping!");
return;
}
for (int screen = 0; screen < gds.length; ++screen) {
GraphicsDevice gd = gds[screen];
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Rectangle bounds = gc.getBounds();
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
Frame frame = new Frame(gc);
frame.setLocation(bounds.x + (bounds.width - SIZE) / 2,
bounds.y + (bounds.height - SIZE) / 2);
frame.setSize(SIZE, SIZE);
frame.setUndecorated(true);
frame.setVisible(true);
// Maximize Frame to reach the struts
frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
Thread.sleep(2000);
Rectangle frameBounds = frame.getBounds();
frame.dispose();
if (bounds.x + insets.left != frameBounds.x
|| bounds.y + insets.top != frameBounds.y
|| bounds.width - insets.right - insets.left != frameBounds.width
|| bounds.height - insets.bottom - insets.top != frameBounds.height) {
throw new RuntimeException("Test FAILED! Wrong screen #" +
screen + " insets: " + insets);
}
}
System.out.println("Test PASSED!");
}