f.setLocationByPlatform(true); Image image = f.getToolkit().createImage(url); ImagePanel imagePanel = new ImagePanel(image); imagePanel.setLayout(new GridLayout(5, 10, 10, 10));
static void centerWindowInScreen(final Window window) { final Dimension screenSize= window.getToolkit().getScreenSize(); final Dimension windowSize= window.getPreferredSize(); window.setLocation( (int) (screenSize.getWidth() / 2 - windowSize.getWidth() / 2), (int) (screenSize.getHeight() / 2 - windowSize.getHeight() / 2)); } /**
static public Insets getScreenInsets(Window wnd) { Insets si; try { if(wnd==null) { si=Toolkit.getDefaultToolkit().getScreenInsets(new Frame().getGraphicsConfiguration()); } else { si=wnd.getToolkit() .getScreenInsets(wnd.getGraphicsConfiguration()); } } catch(NoSuchMethodError thr) { si=new Insets(0,0,0,0); } return si; }
/** * Calculates default location for the specified window. * @return default location for the window * @param window the window location is calculated for. * It should not be null. */ public static Point defaultLocation(Window window) { GraphicsConfiguration gc = window.getGraphicsConfiguration(); Rectangle bounds = gc.getBounds(); Insets insets = window.getToolkit().getScreenInsets(gc); int x = bounds.x + insets.left; int y = bounds.y + insets.top; return new Point(x, y); }
/** * Center the given window within the screen boundaries. * * @param window the window to be centered. */ 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); }
/** * getScreenInsets, This returns the insets of the screen, which are defined by any task bars * that have been set up by the user. This function accounts for multi-monitor setups. If a * window is supplied, then the the monitor that contains the window will be used. If a window * is not supplied, then the primary monitor will be used. */ static public Insets getScreenInsets(Window windowOrNull) { Insets insets; if (windowOrNull == null) { insets = Toolkit.getDefaultToolkit().getScreenInsets(GraphicsEnvironment .getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration()); } else { insets = windowOrNull.getToolkit().getScreenInsets( windowOrNull.getGraphicsConfiguration()); } return insets; }
import java.awt.Frame; import javax.swing.*; class TestFrameSize { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame f = new JFrame("Test Screen Size"); f.setAlwaysOnTop(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); System.out.println(f.getToolkit().getScreenSize()); f.setExtendedState(Frame.MAXIMIZED_BOTH); f.setVisible(true); System.out.println(f.getSize()); } }); } }
/** * getScreenWorkingArea, This returns the working area of the screen. (The working area excludes * any task bars.) This function accounts for multi-monitor setups. If a window is supplied, * then the the monitor that contains the window will be used. If a window is not supplied, then * the primary monitor will be used. */ static public Rectangle getScreenWorkingArea(Window windowOrNull) { Insets insets; Rectangle bounds; if (windowOrNull == null) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); insets = Toolkit.getDefaultToolkit().getScreenInsets(ge.getDefaultScreenDevice() .getDefaultConfiguration()); bounds = ge.getDefaultScreenDevice().getDefaultConfiguration().getBounds(); } else { GraphicsConfiguration gc = windowOrNull.getGraphicsConfiguration(); insets = windowOrNull.getToolkit().getScreenInsets(gc); bounds = gc.getBounds(); } bounds.x += insets.left; bounds.y += insets.top; bounds.width -= (insets.left + insets.right); bounds.height -= (insets.top + insets.bottom); return bounds; }
/** * Returns the standard application icon typically displayed in a window's title bar. */ public static Image getGameIcon(final Window frame) { Image img = null; try { img = frame.getToolkit().getImage(GameRunner.class.getResource("ta_icon.png")); } catch (final Exception ex) { log.log(Level.SEVERE, "ta_icon.png not loaded", ex); } final MediaTracker tracker = new MediaTracker(frame); tracker.addImage(img, 0); try { tracker.waitForAll(); } catch (final InterruptedException ex) { Thread.currentThread().interrupt(); } return img; }
public class test { public static void main(String[] args) { Window wnd = new Window(new Frame()); //wnd.setLocation(100, 100); wnd.setSize(wnd.getToolkit().getScreenSize()); wnd.setBackground(Color.red); wnd.setVisible(true); } }
(state & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH) Insets screenInsets = getToolkit().getScreenInsets(getGraphicsConfiguration()); Rectangle screenSize = getGraphicsConfiguration().getBounds(); Rectangle maxBounds = new Rectangle(screenInsets.left + screenSize.x,
public static void closeWindow(Window w) { w.getToolkit().getSystemEventQueue().postEvent(new WindowEvent(w, WindowEvent.WINDOW_CLOSING)); }
import java.net.*; import java.awt.*; public class QueenApl { Image card; Frame frame; public static void main(String[] args){ QueenApl f = new QueenApl(); } public QueenApl(){ frame = new Frame(); frame.setSize(400,400); try{ URL u = new URL("file:/c:/windows/desktop/carn4.jpg"); card=frame.getToolkit().getImage(u); } catch(MalformedURLException e){ System.out.println("Error in URL!"); System.exit(1); } frame.show(); } public void paint(Graphics g){ g.drawImage(card,120,50,frame); } }
public static void installPalettePrefsHandler(final Preferences prefs, final String name, Window window, int x) { GraphicsConfiguration conf = window.getGraphicsConfiguration(); Rectangle screenBounds = conf.getBounds(); Insets screenInsets = window.getToolkit().getScreenInsets(conf);
Toolkit kit = frame.getToolkit();
GraphicsConfiguration conf = window.getGraphicsConfiguration(); Rectangle screenBounds = conf.getBounds(); Insets screenInsets = window.getToolkit().getScreenInsets(conf);
setBounds(0,0,getToolkit().getScreenSize().width,getToolkit().getScreenSize().height); setVisible(true); Am_I_In_FullScreen = true;
setUndecorated(true); setBounds(0, 0, getToolkit().getScreenSize().width, getToolkit().getScreenSize().height); setVisible(true); Am_I_In_FullScreen = true;
setBounds(-10,-100,getToolkit().getScreenSize().width+30,getToolkit() .getScreenSize().height+110); setVisible(true);
(root.getY() == defaultLocation.getY())) { Dimension screenSize = window.getToolkit().getScreenSize(); Dimension windowSIze = window.getSize();