List of usage examples for java.awt Toolkit getDefaultToolkit
public static synchronized Toolkit getDefaultToolkit()
From source file:Main.java
public static void centerAndSizeWindow(Window win, int fraction, int base) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int width = screenSize.width * fraction / base; int height = screenSize.height * fraction / base; Rectangle rect = new Rectangle((screenSize.width - width) / 2, (screenSize.height - height) / 2, width, height);/* w ww . j a va2 s .com*/ win.setBounds(rect); }
From source file:MainClass.java
public void load() throws MalformedURLException { URL url = new URL("image address"); Image im = Toolkit.getDefaultToolkit().getImage(url); MediaTracker mt = new MediaTracker(this); mt.addImage(im, 0);/*from w w w. j ava2 s . c o m*/ try { mt.waitForID(0); } catch (InterruptedException e) { System.err.println("Unexpected interrupt in waitForID!"); return; } if (mt.isErrorID(0)) { System.err.println("Couldn't load image file " + url); return; } }
From source file:Main.java
/** Returns the screen height (in pixels). */ public static int getScreenHeight() { return Toolkit.getDefaultToolkit().getScreenSize().height; }
From source file:MainClass.java
public void load() throws MalformedURLException { URL url = new URL("image address"); Toolkit t = Toolkit.getDefaultToolkit(); Image im = t.getImage(url);/* w ww . j a v a 2 s . co m*/ MediaTracker mt = new MediaTracker(this); mt.addImage(im, 0); try { mt.waitForID(0); } catch (InterruptedException e) { System.err.println("Unexpected interrupt in waitForID!"); return; } if (mt.isErrorID(0)) { System.err.println("Couldn't load image file " + url); return; } }
From source file:org.jfree.chart.demo.CompassDemo.java
/** * Entry point for the demo application. * * @param args ignored./*w w w .ja v a 2s . c o m*/ */ public static void main(final String[] args) { final CompassDemo panel = new CompassDemo(); final JFrame frame = new JFrame(); frame.getContentPane().setLayout(new BorderLayout(5, 5)); frame.setDefaultCloseOperation(3); frame.setTitle("Compass Demo"); frame.getContentPane().add(panel, BorderLayout.CENTER); frame.setSize(700, 400); final Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2); frame.setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(333, 666)); add(panel);/* w w w .ja va 2 s .c o m*/ pack(); if (Toolkit.getDefaultToolkit().isFrameStateSupported(MAXIMIZED_BOTH)) { setExtendedState(MAXIMIZED_BOTH); } else { Dimension max = Toolkit.getDefaultToolkit().getScreenSize(); max.height -= 20; setSize(max); setLocation(0, 20); } setVisible(true); }
From source file:ImageSize.java
public ImageSize(URL url) { image = Toolkit.getDefaultToolkit().getImage(url); rightSize(); }
From source file:Main.java
/** * Updates {@link #SCREEN_SIZE_PRIMARY } and {@link #SCREEN_SIZE_TOTAL} */// w w w .j av a2 s.c om public static void calculateScreenSizes() { Rectangle totalBounds = new Rectangle(); Rectangle primaryBounds = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); for (int j = 0; j < gs.length; j++) { GraphicsDevice gd = gs[j]; if (gd == ge.getDefaultScreenDevice()) { primaryBounds = new Rectangle(); } GraphicsConfiguration[] gc = gd.getConfigurations(); for (int i = 0; i < gc.length; i++) { Rectangle bounds = gc[i].getBounds(); Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc[i]); bounds.x += screenInsets.left; bounds.y += screenInsets.top; bounds.height -= screenInsets.bottom; bounds.width -= screenInsets.right; totalBounds = totalBounds.union(bounds); if (primaryBounds != null) { primaryBounds = primaryBounds.union(bounds); } } if (primaryBounds != null) { SCREEN_SIZE_PRIMARY = primaryBounds; primaryBounds = null; } } SCREEN_SIZE_TOTAL = totalBounds; }
From source file:Main.java
/** * Centra una finestra all'interno di un'altra * * @param f componente target (finestra esterna) - se null centra nello * schermo/*from w w w . j av a 2 s . co m*/ * @param c componente da centrare (finestra interna) */ public static void centerForm(Component f, Component c) { Rectangle rf = new Rectangle(); ; if (f == null) { rf = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); } else { rf = f.getBounds(); } Rectangle rc = c.getBounds(); int x = (rf.width - rc.width) / 2; if (x < 5) { x = 5; } int y = (rf.height - rc.height) / 2; if (y < 5) { y = 5; } if (f == null) { c.setLocation(x, y); } else { c.setLocation(x + f.getX(), y + f.getY()); } }
From source file:Main.java
/** * Centers a window on screen.// ww w.java 2s . c om * <p> * @param w The window to center. */ public static void centerOnScreen(Window w) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension splashSize = w.getPreferredSize(); w.setLocation(screenSize.width / 2 - (splashSize.width / 2), screenSize.height / 2 - (splashSize.height / 2)); }