/** * Returns the device configuration associated with this * <code>Graphics2D</code>. * @return the device configuration */ public GraphicsConfiguration getDeviceConfiguration() { return GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); }
public static Rectangle[] getScreenBounds() { GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice[] screenDevices = graphicsEnvironment.getScreenDevices(); Rectangle[] screenBounds = new Rectangle[screenDevices.length]; for (int i = 0; i < screenDevices.length; i++) { GraphicsDevice screenDevice = screenDevices[i]; final GraphicsConfiguration defaultConfiguration = screenDevice.getDefaultConfiguration(); screenBounds[i] = defaultConfiguration.getBounds(); } return screenBounds; }
public LwjglAWTInput (LwjglAWTCanvas lwjglAwtCanvas) { this.lwjglAwtCanvas = lwjglAwtCanvas; setListeners(lwjglAwtCanvas.getCanvas()); try { robot = new Robot(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()); } catch (HeadlessException e) { } catch (AWTException e) { } }
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(this); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); timer.start(); Dimension d = field.getPreferredSize(); field.setBounds(e.getX(), e.getY(), d.width, d.height); add(field); GraphicsEnvironment.getLocalGraphicsEnvironment(); private final GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration(); private final Random r = new Random();
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); int width = gd.getDisplayMode().getWidth(); int height = gd.getDisplayMode().getHeight(); jframe.getContentPane().add(glcanvas, BorderLayout.CENTER); jframe.setSize(100, height); jframe.setLocation(width - 100, 0);
JPanel leftSidePanel = new JPanel(); leftSidePanel.setLayout(new GridBagLayout()); getContentPane().add(leftSidePanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()); fontList = new JList(); fontScroll.setViewportView(fontList); getContentPane().add(rightSidePanel, new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); GraphicsDevice[] screenDevices = ge.getScreenDevices(); for (GraphicsDevice gd : screenDevices) { System.out.println(gd + (gd == ge.getDefaultScreenDevice() ? " (default)" : "")); GraphicsConfiguration[] gc = gd.getConfigurations(); // Might want to loop to find largets or bests, instead of taking first one GraphicsConfiguration g = gc[0]; JFrame jf = new JFrame(gd.getDefaultConfiguration()); Canvas c = new Canvas(g); Rectangle gcBounds = g.getBounds(); System.out.println("SIZE: " + gcBounds); jf.getContentPane().add(c); jf.setSize(gcBounds.width, gcBounds.height); jf.setVisible(true); } } }
public void run() { JFrame frame = new JFrame(pTitle); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationByPlatform(true); JPanel pane = new JPanel(new BorderLayout()); GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); BufferedImageIcon icon = new BufferedImageIcon(ImageUtil.accelerate(pImage, gc)); JScrollPane scroll = new JScrollPane(new JLabel(icon)); scroll.setBorder(null); pane.add(scroll); frame.setContentPane(pane); frame.pack(); frame.setVisible(true); } });
public static void showCenterScreen(Window window) { try { Rectangle bound = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().getBounds(); window.setLocation(bound.x + (bound.width - window.getWidth()) / 2, bound.y + (bound.height - window.getHeight()) / 2); } catch (Exception e) { LOGGER.error("Cannot center the window to the screen", e); //$NON-NLS-1$ } window.setVisible(true); }
public static void main(String[] args) { JFrame test = new JFrame("Tab test"); test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); test.setSize(400, 400); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); //If translucent windows aren't supported, exit. /* if (!gd.isWindowTranslucencySupported(TRANSLUCENT)) { System.err.println( "Translucency is not supported"); System.exit(0); }*/ DraggableTabbedPane tabs = new DraggableTabbedPane(); tabs.addTab("One", new JButton("One")); tabs.addTab("Two", new JButton("Two")); tabs.addTab("Three", new JButton("Three")); tabs.addTab("Four", new JButton("Four")); test.add(tabs); test.setVisible(true); } }
import java.awt.*; import javax.swing.*; public class JFrameExtended { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle maxBounds = env.getMaximumWindowBounds(); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setBounds(maxBounds); f.setVisible(true); System.out.println("Frame size: " + f.getSize()); } }); } }
public static void main(String[] a) { GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment(); JPanel contentPane = new JPanel(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); for (Font i : e.getAllFonts()) { String name = i.getFontName(); //if (name.startsWith("HelveticaNeue")) { JLabel label = new JLabel(name); label.setFont(i.deriveFont(18f)); contentPane.add(label); //} } JFrame frame = new JFrame("Fonts"); frame.setContentPane(ViewUtil.getClearBorderlessScrollPane(contentPane)); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }
@Override public void startWindowDialog(Window window) { GraphicsDevice localDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); if (localDevice.getFullScreenWindow() != null) { localDevice.setFullScreenWindow(null); } window.setVisible(true); }
import java.awt.*; import javax.swing.*; public class Test extends JFrame { public Test() { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); this.setMaximizedBounds(env.getMaximumWindowBounds()); this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH); } public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); Test t = new Test(); t.setVisible(true); } }
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); for (int j = 0; j < gs.length; j++) { JPanel fontNameCol = new JPanel(new GridLayout(0, 1, 2, 2)); JPanel fontExampleCol = new JPanel(new GridLayout(0, 1, 2, 2)); fontTable.add(fontNameCol, BorderLayout.WEST); fontTable.add(fontExampleCol, BorderLayout.CENTER); for (int ii = 0; ii < fonts.length; ii++) { fontNameCol.add(new JLabel(fonts[ii])); fontExampleCol.add(getExampleOfFont(fonts[ii])); p.setPreferredSize(new Dimension(400, 400)); JFrame f = new JFrame("Properties"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.getContentPane().add(p, BorderLayout.CENTER); f.pack(); f.setSize(600, 500); f.setLocationRelativeTo(null); f.setVisible(true);
/** * 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 ); }
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); int width = gd.getDisplayMode().getWidth(); int height = gd.getDisplayMode().getHeight(); jframe.getContentPane().add(glcanvas, BorderLayout.CENTER); jframe.setSize(100, height); jframe.setLocation(width - 100, 0);
JPanel leftSidePanel = new JPanel(); leftSidePanel.setLayout(new GridBagLayout()); getContentPane().add(leftSidePanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()); fontList = new JList(); fontScroll.setViewportView(fontList); getContentPane().add(rightSidePanel, new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
public LwjglAWTInput (LwjglAWTCanvas lwjglAwtCanvas) { this.lwjglAwtCanvas = lwjglAwtCanvas; setListeners(lwjglAwtCanvas.getCanvas()); try { robot = new Robot(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()); } catch (HeadlessException e) { } catch (AWTException e) { } }
public void run() { JFrame frame = new JFrame(pTitle); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationByPlatform(true); JPanel pane = new JPanel(new BorderLayout()); GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); BufferedImageIcon icon = new BufferedImageIcon(ImageUtil.accelerate(pImage, gc)); JScrollPane scroll = new JScrollPane(new JLabel(icon)); scroll.setBorder(null); pane.add(scroll); frame.setContentPane(pane); frame.pack(); frame.setVisible(true); } });