List of usage examples for javax.swing JInternalFrame getSize
public Dimension getSize()
From source file:Main.java
/** * Displays a specified <code>JFileChooser</code> in a JInternalFrame. <br /> * The JInternalFrame will close when the dialog is closed. <br /> * /*ww w.ja v a 2s .c o m*/ * @param desktop the JDesktopPane on which to display the JFileChooser * @param ch the JFileChooser to display */ public static void showInternalFileChooser(JDesktopPane desktop, final JFileChooser ch) { final JInternalFrame frm = new JInternalFrame(ch.getDialogTitle()); frm.setClosable(true); frm.setResizable(true); frm.setLayout(new BorderLayout()); frm.add(ch, BorderLayout.CENTER); frm.setVisible(true); frm.pack(); Dimension size = frm.getSize(); frm.setLocation(desktop.getWidth() / 2 - size.width / 2, desktop.getHeight() / 2 - size.height / 2); desktop.add(frm, 0); ch.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { frm.dispose(); ch.removeActionListener(this); } }); try { frm.setSelected(true); } catch (java.beans.PropertyVetoException e) { } }
From source file:Main.java
/** * Creates (and displays) a JInternalFrame for a specified component. <br /> * The size of the JInternalFrame will be <code>frameSize</code>. <br /> * The frame is <i>just</i> closeable. <br /> * /* w w w . ja v a 2s.c om*/ * @param desktop the JDesktopPane * @param comp the component to display in the created frame * @param title the title of the frame * @param frameSize the size of the frame * @return the created and displayed frame */ public static JInternalFrame showInternalFrame(JDesktopPane desktop, JComponent comp, String title, Dimension frameSize) { JInternalFrame frm = new JInternalFrame(title); frm.setClosable(true); frm.setLayout(new BorderLayout()); frm.add(comp, BorderLayout.CENTER); frm.setSize(frameSize); frm.setVisible(true); Dimension size = frm.getSize(); frm.setLocation(desktop.getWidth() / 2 - size.width / 2, desktop.getHeight() / 2 - size.height / 2); desktop.add(frm, 0); try { frm.setSelected(true); } catch (java.beans.PropertyVetoException e) { } return frm; }
From source file:Main.java
/** * Creates (and displays) a JInternalFrame for a specified component. <br /> * The size of the JInternalFrame will be setted with calling <code>pack()</code>. <br /> * //from w w w.j ava 2s . c o m * @param desktop the JDesktopPane * @param comp the component to display in the created frame * @param title the title of the frame * @param frameSize the size of the frame * @return the created and displayed frame */ public static JInternalFrame showInternalFrame(JDesktopPane desktop, JComponent comp, String title) { JInternalFrame frm = new JInternalFrame(title); frm.setClosable(true); frm.setLayout(new BorderLayout()); frm.add(comp, BorderLayout.CENTER); desktop.add(frm, 0); frm.pack(); frm.setVisible(true); Dimension size = frm.getSize(); frm.setLocation(desktop.getWidth() / 2 - size.width / 2, desktop.getHeight() / 2 - size.height / 2); try { frm.setSelected(true); } catch (java.beans.PropertyVetoException e) { } return frm; }
From source file:Main.java
/** * Shows a specified JInternalFrame in the middle of the specified JDesktopPane. <br /> * The size of the JInternalFrame will be <code>frameSize</code>. <br /> * The frame is <i>just</i> closeable. <br /> * /*from www . j a va 2 s. com*/ * @param desktop the JDesktopPane * @param frm the JInternalFrame * @param content the component which will be added to the JInternalFrame * @param frameSize the size of the JInternalFrame */ public static void showInternalFrame(JDesktopPane desktop, JInternalFrame frm, JComponent content, Dimension frameSize) { frm.setClosable(true); frm.setLayout(new BorderLayout()); frm.add(content, BorderLayout.CENTER); frm.setSize(frameSize); frm.setVisible(true); Dimension size = frm.getSize(); frm.setLocation(desktop.getWidth() / 2 - size.width / 2, desktop.getHeight() / 2 - size.height / 2); desktop.add(frm, 0); try { frm.setSelected(true); } catch (java.beans.PropertyVetoException e) { } }
From source file:com.opendoorlogistics.studio.AppFrame.java
@Override public void addInternalFrame(JInternalFrame frame, FramePlacement placement) { desktopPane.add(frame);/*from www.ja va 2 s .co m*/ frame.pack(); frame.setVisible(true); // if(ScriptEditor.class.isInstance(frame)){ // try { // frame.setMaximum(true); // } catch (PropertyVetoException e) { // } // } // else{ // WindowState state = PreferencesManager.getSingleton().getWindowState(frame) if (placement == FramePlacement.AUTOMATIC) { boolean placed = false; if (ODLInternalFrame.class.isInstance(frame)) { ODLInternalFrame odlFrame = (ODLInternalFrame) frame; placed = odlFrame.placeInLastPosition(desktopScrollPane.getViewport().getBounds()); } if (!placed) { LayoutUtils.placeInternalFrame(desktopPane, frame); } } else if (placement == FramePlacement.CENTRAL) { Dimension desktopSize = desktopPane.getSize(); Dimension frameSize = frame.getSize(); int x = (desktopSize.width - frameSize.width) / 2; int y = (desktopSize.height - frameSize.height) / 2; frame.setLocation(x, y); } else if (placement == FramePlacement.CENTRAL_RANDOMISED) { Dimension desktopSize = desktopPane.getSize(); Dimension frameSize = frame.getSize(); Dimension remaining = new Dimension(Math.max(0, desktopSize.width - frameSize.width), Math.max(0, desktopSize.height - frameSize.height)); Dimension halfRemaining = new Dimension(remaining.width / 2, remaining.height / 2); Random random = new Random(); int x = remaining.width / 4 + random.nextInt(halfRemaining.width); int y = remaining.height / 4 + random.nextInt(halfRemaining.height); frame.setLocation(x, y); } frame.toFront(); }
From source file:com.tag.FramePreferences.java
@SuppressWarnings("serial") public FramePreferences(final JInternalFrame frame, String pathName) { setFrame(new Frame() { @Override// w w w . j ava2 s .c o m public synchronized int getExtendedState() { if (frame.isMaximum()) { return Frame.MAXIMIZED_BOTH; } else if (frame.isIcon()) { return Frame.ICONIFIED; } else { return Frame.NORMAL; } } @Override public synchronized void setExtendedState(int state) { try { switch (state) { case Frame.MAXIMIZED_HORIZ: case Frame.MAXIMIZED_VERT: case Frame.MAXIMIZED_BOTH: frame.setMaximum(true); break; case Frame.ICONIFIED: frame.setIcon(true); break; case Frame.NORMAL: frame.setIcon(false); frame.setMaximum(false); break; } } catch (PropertyVetoException e) { e.printStackTrace(); } } @Override public synchronized void addWindowStateListener(final WindowStateListener l) { final Frame source = this; frame.addInternalFrameListener(new InternalFrameAdapter() { @Override public void internalFrameIconified(InternalFrameEvent e) { l.windowStateChanged(new WindowEvent(source, WindowEvent.WINDOW_ICONIFIED)); } @Override public void internalFrameDeiconified(InternalFrameEvent e) { l.windowStateChanged(new WindowEvent(source, WindowEvent.WINDOW_DEICONIFIED)); } }); } @Override public synchronized void removeWindowStateListener(WindowStateListener l) { super.removeWindowStateListener(l); } @Override public GraphicsConfiguration getGraphicsConfiguration() { return frame.getGraphicsConfiguration(); } public Point getLocation() { return frame.getLocation(); } @Override public void setLocation(Point p) { frame.setLocation(p); } @Override public Dimension getSize() { return frame.getSize(); } @Override public void setSize(Dimension size) { frame.setSize(size); } @Override public synchronized void addComponentListener(ComponentListener l) { frame.addComponentListener(l); } @Override public synchronized void removeComponentListener(ComponentListener l) { frame.addComponentListener(l); } }); setPathName(pathName); }
From source file:org.intermine.common.swing.WindowUtils.java
/** * Centre the internal frame <code>win</code> over the internal * frame <code>parent</code>. * /* w w w .j a v a 2 s. co m*/ * @param win The JInternalFrame to position. * @param parent The reference JInternalFrame. */ public static void centreOverFrame(JInternalFrame win, JInternalFrame parent) { Rectangle parentBounds = parent.getBounds(); Dimension windowSize = win.getSize(); int x = (parentBounds.width - windowSize.width) / 2; int y = (parentBounds.height - windowSize.height) / 2; x = Math.max(0, x + parentBounds.x); y = Math.max(0, y + parentBounds.y); win.setLocation(x, y); }