List of usage examples for javax.swing JFrame getInsets
public Insets getInsets()
From source file:Main.java
public static void main(String[] args) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle bounds = env.getMaximumWindowBounds(); System.out.println("Screen Bounds: " + bounds); GraphicsDevice screen = env.getDefaultScreenDevice(); GraphicsConfiguration config = screen.getDefaultConfiguration(); System.out.println("Screen Size : " + config.getBounds()); JFrame frame = new JFrame("Frame Info"); System.out.println("Frame Insets : " + frame.getInsets()); frame.setSize(200, 200);//from w ww. jav a2s.co m System.out.println("Frame Insets : " + frame.getInsets()); frame.setVisible(true); System.out.println("Frame Size : " + frame.getSize()); System.out.println("Frame Insets : " + frame.getInsets()); System.out.println("Content Size : " + frame.getContentPane().getSize()); }
From source file:PNGDecoder.java
public static void main(String[] args) throws Exception { String name = "logo.png"; if (args.length > 0) name = args[0];//from w ww . j ava2 s .c o m InputStream in = PNGDecoder.class.getResourceAsStream(name); final BufferedImage image = PNGDecoder.decode(in); in.close(); JFrame f = new JFrame() { public void paint(Graphics g) { Insets insets = getInsets(); g.drawImage(image, insets.left, insets.top, null); } }; f.setVisible(true); Insets insets = f.getInsets(); f.setSize(image.getWidth() + insets.left + insets.right, image.getHeight() + insets.top + insets.bottom); }
From source file:layout.AbsoluteLayoutDemo.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from ww w. j a v a2 s. com*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("AbsoluteLayoutDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. addComponentsToPane(frame.getContentPane()); //Size and display the window. Insets insets = frame.getInsets(); frame.setSize(300 + insets.left + insets.right, 125 + insets.top + insets.bottom); frame.setVisible(true); }
From source file:AbsoluteLayoutDemo.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. *//*from www . j a v a2s. c o m*/ private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("AbsoluteLayoutDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. addComponentsToPane(frame.getContentPane()); //Size and display the window. Insets insets = frame.getInsets(); frame.setSize(300 + insets.left + insets.right, 125 + insets.top + insets.bottom); frame.setVisible(true); }
From source file:com.mirth.connect.plugins.imageviewer.ImageViewer.java
public void viewAttachments(String channelId, Long messageId, String attachmentId) { JFrame frame = new JFrame("Image Viewer"); try {// w ww .ja v a 2 s .com Attachment attachment = parent.mirthClient.getAttachment(channelId, messageId, attachmentId); byte[] rawData = attachment.getContent(); ByteArrayInputStream bis = new ByteArrayInputStream(rawData); image = ImageIO.read(new Base64InputStream(bis)); JScrollPane pictureScrollPane = new JScrollPane(new JLabel(new ImageIcon(image))); pictureScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); pictureScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); frame.add(pictureScrollPane); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } }); frame.pack(); int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); // Resize the frame so that it fits and scrolls images larger than // 800x600 properly. if (imageWidth > 800 || imageHeight > 600) { int width = imageWidth; int height = imageHeight; if (imageWidth > 800) { width = 800; } if (imageHeight > 600) { height = 600; } // Also add the scrollbars to the window width if necessary. Integer scrollBarWidth = (Integer) UIManager.get("ScrollBar.width"); int verticalScrollBar = 0; int horizontalScrollBar = 0; if (width == 800) { horizontalScrollBar = scrollBarWidth.intValue(); } if (height == 600) { verticalScrollBar = scrollBarWidth.intValue(); } // Also add the window borders to the width. width = width + frame.getInsets().left + frame.getInsets().right + verticalScrollBar; height = height + frame.getInsets().top + frame.getInsets().bottom + horizontalScrollBar; frame.setSize(width, height); } Dimension dlgSize = frame.getSize(); Dimension frmSize = parent.getSize(); Point loc = parent.getLocation(); if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) { frame.setLocationRelativeTo(null); } else { frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); } frame.setVisible(true); } catch (Exception e) { parent.alertThrowable(parent, e); } }
From source file:edu.ku.brc.ui.UIHelper.java
/** * Center and make the window visible//from w w w .ja v a2s . c o m * @param window the window to center * @param width sets the dialog to this width (can be null) * @param height sets the dialog to this height (can be null) */ public static void centerWindow(final java.awt.Window window, final Integer width, final Integer height) { JFrame topFrame = (JFrame) UIRegistry.getTopWindow(); Insets screenInsets = null; Rectangle screenRect = null; if (width != null || height != null) { Dimension s = window.getSize(); if (width != null) s.width = width; if (height != null) s.height = height; window.setSize(s); } // if there is a registered TOPFRAME, and it's not the same as the window being passed in... if (topFrame != null && topFrame != window) { screenRect = topFrame.getBounds(); screenInsets = topFrame.getInsets(); } else { screenRect = window.getGraphicsConfiguration().getBounds(); screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(window.getGraphicsConfiguration()); } // Make sure we don't place the demo off the screen. int centerWidth = screenRect.width < window.getSize().width ? screenRect.x : screenRect.x + screenRect.width / 2 - window.getSize().width / 2; int centerHeight = screenRect.height < window.getSize().height ? screenRect.y : screenRect.y + screenRect.height / 2 - window.getSize().height / 2; centerHeight = centerHeight < screenInsets.top ? screenInsets.top : centerHeight; window.setLocation(centerWidth, centerHeight); }