List of usage examples for java.awt Toolkit getDefaultToolkit
public static synchronized Toolkit getDefaultToolkit()
From source file:Main.java
/** Repositions a frame to be centered on the screen */ public static void center(Frame frame) { Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screen = tk.getScreenSize(); Dimension win = frame.getSize(); //frame.setSize(screenWidth / 2, screenHeight / 2); frame.setLocation((screen.width - win.width) / 2, (screen.height - win.height) / 2); }
From source file:Main.java
public Main() { setTitle("CenteredFrame"); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/*from w ww. ja v a 2 s . c om*/ } }); Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); int screenHeight = screenSize.height; int screenWidth = screenSize.width; setSize(screenWidth / 2, screenHeight / 2); setLocation(screenWidth / 4, screenHeight / 4); }
From source file:CenteredFrame.java
public CenteredFrame() { setTitle("CenteredFrame"); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/*from w ww. j a v a 2 s . co m*/ } }); Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); int screenHeight = screenSize.height; int screenWidth = screenSize.width; setSize(screenWidth / 2, screenHeight / 2); setLocation(screenWidth / 4, screenHeight / 4); }
From source file:Main.java
public void componentMoved(ComponentEvent evt) { if (locked)//from w w w . j ava 2s . c om return; Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); int nx = evt.getComponent().getX(); int ny = evt.getComponent().getY(); // top if (ny < 0 + sd) { ny = 0; } // left if (nx < 0 + sd) { nx = 0; } // right if (nx > size.getWidth() - evt.getComponent().getWidth() - sd) { nx = (int) size.getWidth() - evt.getComponent().getWidth(); } // bottom if (ny > size.getHeight() - evt.getComponent().getHeight() - sd) { ny = (int) size.getHeight() - evt.getComponent().getHeight(); } locked = true; evt.getComponent().setLocation(nx, ny); locked = false; }
From source file:Main.java
public Main() { JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5)); ImageIcon icon = new ImageIcon(Toolkit.getDefaultToolkit().getImage("matte.gif")); simplePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), BorderFactory.createMatteBorder(-1, -1, -1, -1, icon))); simplePanel.add(new JLabel("Examples"), JLabel.CENTER); add(simplePanel);/*from w w w . j a v a2 s . c om*/ }
From source file:SwingUtils.java
public static void centerOnScreen(Window window, boolean packFrame) { //Validate frames that have preset sizes //Pack frames that have useful preferred size info, e.g. from their layout if (packFrame) { window.pack();//w w w . jav a2 s . c om } else { window.validate(); } //Center the frame window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = window.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } window.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); }
From source file:flushMe.java
flushMe() { super("Flushing"); im = Toolkit.getDefaultToolkit().getImage("flush.gif"); setSize(175, 225); }
From source file:ja.lingo.application.util.plaf.JaLingoLookAndFeel.java
public static void install(int fontSize, String fontFace) { // children dynamic re-layout on resize Toolkit.getDefaultToolkit().setDynamicLayout(true); // kunstoff//w w w.j a v a2s . c o m JaLingoLookAndFeel laf = new JaLingoLookAndFeel(); setCurrentTheme(new RainyTheme(fontSize, fontFace)); setCurrentGradientTheme(new RainyGradientTheme()); //LookAndFeel laf = new WindowsLookAndFeel(); // children LF //Plastic3DLookAndFeel laf = new Plastic3DLookAndFeel(); //Plastic3DLookAndFeel.setMyCurrentTheme( new ExperienceBlue() ); try { //UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() ); UIManager.setLookAndFeel(laf); //Wrapper.wrap(); } catch (Exception e) { LOG.warn("Could not initialize LF", e); } }
From source file:Main.java
/** * Retrieves the bounds represents the available space on the Window's display that is not used up by things like * the task bar or dock./*from www .j a va 2 s. co m*/ * * @param window * The window to center * @return Bounds of the display's available space */ public static Rectangle getBoundsOfAvailableDisplaySpace(Window window) { GraphicsConfiguration graphicsConfigToUse = window.getGraphicsConfiguration(); // If the Window does not have a GraphicsConfiguration yet (perhaps when the Window is not set up yet) then use the default screen's GraphicsConfiguration. if (graphicsConfigToUse == null) { graphicsConfigToUse = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); } Rectangle boundsOfEntireScreen = graphicsConfigToUse.getBounds(); Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfigToUse); return new Rectangle(screenInsets.left, screenInsets.top, boundsOfEntireScreen.width - screenInsets.left - screenInsets.right, boundsOfEntireScreen.height - screenInsets.top - screenInsets.bottom); }
From source file:SplashScreen.java
License:asdf
public SplashScreen(int d) { duration = d;/*from ww w . j a v a2s . c o m*/ JPanel content = (JPanel) getContentPane(); content.setBackground(Color.white); int width = 450; int height = 115; Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int x = (screen.width - width) / 2; int y = (screen.height - height) / 2; setBounds(x, y, width, height); content.add(new JLabel("asdf"), BorderLayout.CENTER); Color oraRed = new Color(156, 20, 20, 255); content.setBorder(BorderFactory.createLineBorder(oraRed, 10)); setVisible(true); try { Thread.sleep(duration); } catch (Exception e) { } setVisible(false); }