List of usage examples for javax.swing JInternalFrame reshape
@SuppressWarnings("deprecation") public void reshape(int x, int y, int width, int height)
From source file:InternalFrameTest.java
/** * Cascades the non-iconified internal frames of the desktop. */// www .j a v a 2s. c om public void cascadeWindows() { int x = 0; int y = 0; int width = desktop.getWidth() / 2; int height = desktop.getHeight() / 2; for (JInternalFrame frame : desktop.getAllFrames()) { if (!frame.isIcon()) { try { // try to make maximized frames resizable; this might be vetoed frame.setMaximum(false); frame.reshape(x, y, width, height); x += frameDistance; y += frameDistance; // wrap around at the desktop edge if (x + width > desktop.getWidth()) x = 0; if (y + height > desktop.getHeight()) y = 0; } catch (PropertyVetoException e) { } } } }
From source file:InternalFrameTest.java
/** * Tiles the non-iconified internal frames of the desktop. */// w w w .j ava 2s . com public void tileWindows() { // count frames that aren't iconized int frameCount = 0; for (JInternalFrame frame : desktop.getAllFrames()) if (!frame.isIcon()) frameCount++; if (frameCount == 0) return; int rows = (int) Math.sqrt(frameCount); int cols = frameCount / rows; int extra = frameCount % rows; // number of columns with an extra row int width = desktop.getWidth() / cols; int height = desktop.getHeight() / rows; int r = 0; int c = 0; for (JInternalFrame frame : desktop.getAllFrames()) { if (!frame.isIcon()) { try { frame.setMaximum(false); frame.reshape(c * width, r * height, width, height); r++; if (r == rows) { r = 0; c++; if (c == cols - extra) { // start adding an extra row rows++; height = desktop.getHeight() / rows; } } } catch (PropertyVetoException e) { } } } }
From source file:InternalFrameTest.java
/** * Creates an internal frame on the desktop. * @param c the component to display in the internal frame * @param t the title of the internal frame. *//*from w w w .j a v a 2 s.c o m*/ public void createInternalFrame(Component c, String t) { final JInternalFrame iframe = new JInternalFrame(t, true, // resizable true, // closable true, // maximizable true); // iconifiable iframe.add(c, BorderLayout.CENTER); desktop.add(iframe); iframe.setFrameIcon(new ImageIcon("document.gif")); // add listener to confirm frame closing iframe.addVetoableChangeListener(new VetoableChangeListener() { public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException { String name = event.getPropertyName(); Object value = event.getNewValue(); // we only want to check attempts to close a frame if (name.equals("closed") && value.equals(true)) { // ask user if it is ok to close int result = JOptionPane.showInternalConfirmDialog(iframe, "OK to close?", "Select an Option", JOptionPane.YES_NO_OPTION); // if the user doesn't agree, veto the close if (result != JOptionPane.YES_OPTION) throw new PropertyVetoException("User canceled close", event); } } }); // position frame int width = desktop.getWidth() / 2; int height = desktop.getHeight() / 2; iframe.reshape(nextFrameX, nextFrameY, width, height); iframe.show(); // select the frame--might be vetoed try { iframe.setSelected(true); } catch (PropertyVetoException e) { } frameDistance = iframe.getHeight() - iframe.getContentPane().getHeight(); // compute placement for next frame nextFrameX += frameDistance; nextFrameY += frameDistance; if (nextFrameX + width > desktop.getWidth()) nextFrameX = 0; if (nextFrameY + height > desktop.getHeight()) nextFrameY = 0; }