List of usage examples for java.awt GraphicsEnvironment getLocalGraphicsEnvironment
public static GraphicsEnvironment getLocalGraphicsEnvironment()
From source file:Main.java
/** Returns the Screen resolution of all available displays. If ther's only one display you might use: {@link #getScreenSize()} * @return Screen resolution of all available displays. * @see #getScreenSize()/*from w w w .ja v a 2 s . co m*/ */ public static Dimension[] getScreenSizes() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); // Get size of each screen Dimension[] dimension = new Dimension[gs.length]; for (int i = 0; i < gs.length; i++) { DisplayMode dm = gs[i].getDisplayMode(); dimension[i] = new Dimension(dm.getWidth(), dm.getHeight()); } return dimension; }
From source file:Main.java
public static void importFont(InputStream stream) { try {// w w w. j a v a 2 s . c o m Font font1 = Font.createFont(Font.TRUETYPE_FONT, stream); GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font1); } catch (FontFormatException ex) { throw new RuntimeException(ex); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:Main.java
/** * Gets the screen resolution in an integer array. * //from w w w . j a va2 s . co m * @return an int array containing two entries, the width and the height in * pixels. */ public static int[] getScreenResolution() { final int[] result = new int[2]; final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice gd = ge.getDefaultScreenDevice(); result[0] = gd.getDisplayMode().getWidth(); result[1] = gd.getDisplayMode().getHeight(); return result; }
From source file:Main.java
/** * Used for getting the actual bound of the monitor that contains Point p * * @param p - point to check monitor for * @return - current monitor bounds/* w w w . ja v a 2s . c om*/ */ public static Rectangle getScreenBoundsForPoint(Point p) { Rectangle bounds; GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsConfiguration graphicsConfiguration = null; for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) { if (gd.getDefaultConfiguration().getBounds().contains(p)) { graphicsConfiguration = gd.getDefaultConfiguration(); break; } } if (graphicsConfiguration != null) { bounds = graphicsConfiguration.getBounds(); Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfiguration); bounds.x += screenInsets.left; bounds.y += screenInsets.top; bounds.height -= screenInsets.bottom; bounds.width -= screenInsets.right; } else { bounds = env.getMaximumWindowBounds(); } return (bounds); }
From source file:Main.java
/** * Center the given window within the screen boundaries. * * @param window the window to be centered. *//*from w w w . j a v a2s. c om*/ public static void centerWindow(Window window) { Rectangle bounds; try { bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().getBounds(); } catch (Throwable t) { Toolkit tk = window.getToolkit(); Dimension ss = tk.getScreenSize(); bounds = new Rectangle(ss); } int width = window.getWidth(), height = window.getHeight(); window.setBounds(bounds.x + (bounds.width - width) / 2, bounds.y + (bounds.height - height) / 2, width, height); }
From source file:DisplayModeModel.java
public static void main(String[] args) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] devices = env.getScreenDevices(); // REMIND : Multi-monitor full-screen mode not yet supported for (int i = 0; i < 1 /* devices.length */; i++) { DisplayModeTest test = new DisplayModeTest(devices[i]); test.initComponents(test.getContentPane()); test.begin();//from ww w . j av a 2s . co m } }
From source file:Main.java
public static GraphicsDevice defaultScreenDevice() { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); if (env == null) throw new UnsupportedOperationException("Could not get Local Graphics Environment"); GraphicsDevice dev = env.getDefaultScreenDevice(); if (dev == null) throw new UnsupportedOperationException("Could not get Default Graphics Device"); return dev;/*from ww w . jav a 2 s. c om*/ }
From source file:Main.java
/** * returns the virtual screensize in a multimonitor system * //w ww .j a v a2 s . c o m * @return */ public static Dimension getVirtualScreenSize() { Rectangle virtualBounds = new Rectangle(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); for (int j = 0; j < gs.length; j++) { GraphicsDevice gd = gs[j]; GraphicsConfiguration[] gc = gd.getConfigurations(); for (int i = 0; i < gc.length; i++) { virtualBounds = virtualBounds.union(gc[i].getBounds()); } } return virtualBounds.getSize(); }
From source file:Main.java
private static void initScreenDevices() { final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); screenDevices = graphicsEnvironment.getScreenDevices(); }
From source file:Main.java
/** * Check whether GUI present or not./* www .j a va2 s . co m*/ */ public static boolean isGUI() { boolean retVal = false; try { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); if (gs.length > 0) { retVal = true; } } catch (Throwable t) { } return retVal; }