List of usage examples for javax.swing JInternalFrame getWidth
@BeanProperty(bound = false) public int getWidth()
From source file:Utils.java
/** * <p/>//ww w.j a va2 s.co m * Returns the <code>Point</code> at which a window should be placed to * center that window on the given desktop. * </p> * <p/> * Some thought was taken as to whether to implement a method such as this, * or to simply make a method that, given a window, will center it. It was * decided that it is better to not alter an object within a method. * </p> * * @param window The window (JInternalFrame) to calculate the center point * for. This object can not be null. * * @return the <code>Point</code> at which the window should be placed to * center that window on the given desktop */ public static Point getPointForCentering(JInternalFrame window) { try { //assert window != null; Point mousePoint = MouseInfo.getPointerInfo().getLocation(); GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); for (GraphicsDevice device : devices) { Rectangle bounds = device.getDefaultConfiguration().getBounds(); //check to see if the mouse cursor is within these bounds if (mousePoint.x >= bounds.x && mousePoint.y >= bounds.y && mousePoint.x <= (bounds.x + bounds.width) && mousePoint.y <= (bounds.y + bounds.height)) { //this is it int screenWidth = bounds.width; int screenHeight = bounds.height; int width = window.getWidth(); int height = window.getHeight(); return new Point(((screenWidth - width) / 2) + bounds.x, ((screenHeight - height) / 2) + bounds.y); } } } catch (Exception e) { } return new Point(0, 0); }
From source file:Main.java
public Main() { JInternalFrame frame1 = new JInternalFrame("Frame 1", true, true, true, true); JInternalFrame frame2 = new JInternalFrame("Frame 2", true, true, true, true); frame1.getContentPane().add(new JLabel("Frame 1 contents...")); frame1.pack();//from w w w . j ava 2s .c o m frame1.setVisible(true); frame2.getContentPane().add(new JLabel("Frame 2 contents...")); frame2.pack(); frame2.setVisible(true); int x2 = frame1.getX() + frame1.getWidth() + 10; int y2 = frame1.getY(); frame2.setLocation(x2, y2); desktopPane.add(frame1); desktopPane.add(frame2); this.add(desktopPane, BorderLayout.CENTER); this.setMinimumSize(new Dimension(300, 300)); }
From source file:SampleDesktop.java
public void dragFrame(JComponent f, int x, int y) { if (f instanceof JInternalFrame) { // Deal only w/internal frames JInternalFrame frame = (JInternalFrame) f; JDesktopPane desk = frame.getDesktopPane(); Dimension d = desk.getSize(); // Nothing all that fancy below, just figuring out how to adjust // to keep the frame on the desktop. if (x < 0) { // too far left? x = 0; // flush against the left side } else {/*from w w w . j a va 2 s . co m*/ if (x + frame.getWidth() > d.width) { // too far right? x = d.width - frame.getWidth(); // flush against right side } } if (y < 0) { // too high? y = 0; // flush against the top } else { if (y + frame.getHeight() > d.height) { // too low? y = d.height - frame.getHeight(); // flush against the // bottom } } } // Pass along the (possibly cropped) values to the normal drag handler. super.dragFrame(f, x, y); }