![]() ![]() ![]() |
10
Multiple Document Frame
Features of JCMDIPane and JCMDIFrame
Properties
Methods
Examples
10.1 Features of JCMDIPane and JCMDIFrame
The Multiple Document Interface (MDI) model is a common way of organizing and presenting information in windows-style environments. The MDI model makes it possible to arrange multiple child windows inside a parent window, such as multiple files in a text editor, or multiple charts in one frame. In effect, the parent window becomes the desktop within which the children operate. Before Swing, there was no way of building MDI applications using the Abstract Windowing Toolkit (AWT).
If you were limited to using raw Swing components, you would likely build your primary GUI application within a
JFrame
. The container used to hold a multiple-document interface is aJDesktopPane
, which you would put into the content pane of yourJFrame
. Finally, you would addJInternalFrame
s as needed for your document windows.The JClass Elements components
JCMDIPane
andJCMDIFrame
augment the functionality ofJDesktopPane
andJInternalFrame
respectively. Simply replaceJDesktopPane
withJCMDIPane
, andJInternalFrame
withJCMDIFrame
, and your job is almost complete! The only other thing you need to do is to use thesetMDIMenuBar()
method to set individual menu bars on each of your internal frames. These menu bars will replace the default menu bar that you set onJCMDIPane
.
JClass Elements's multiple document
JCMDIPane
interface component extends Swing'sJDesktopPane
view to provide the following standard MDI features:Figure 37 : The differences between a JCMDIPane (lower image) and a JInternalFrame (upper image).
- True maximization. Instead of keeping two menu bars when an internal pane is maximized,
JCMDIPane
optimizes screen real estate by placing menus on the desktop's menu bar. All necessary functionality is preserved.- Automatically adds a localized Windows menu containing two sections.
- The upper section of the Windows menu allows you to select from one of three window tiling algorithms: Cascade, Tile Horizontally, or Tile Vertically.
- The upper section of the Windows menu also allows you to Minimize/Maximize the selected frame, or to (re)Arrange Icons of the minimized frames.
- The lower section of the Windows menu provides a list of the titles of the internal frames, giving the user the ability to switch focus to any internal frame by selecting its name from the menu.
- Adds unmaximize/close icons to the far right of the menu bar when one of the frames is maximized.
Public classes:
JCMDIPane
- subclass ofJDesktopPane
JCMDIFrame
- subclass ofJInternalFrame
JCMDIPane
is API compatible withJDesktopPane
, but the behavior differs in that it automatically generates a Windows menu on the first toolbar it finds in its ancestral hierarchy. This Windows menu has arrangement options Cascade, Tile Horizontally, Tile Vertically, and Arrange Icons, and a selectable list of all the existing internal frames. When frames are maximized the first child of an internal frame's content pane is reparented to a panel that is mapped on top of all the frames so that the maximized frame makes maximal use of the existing window real estate.Default dragging and resizing behavior is done speedily by drawing wire frames.
JCMDIFrame
, when callinggetContentPane
, returns an additional child that is the single child of the true content pane. This is done for easy reparenting purposes as well as for support routines that aid in the manipulation of this child.
Figure 38 : A JFrame containing a JCMDIPane and multiple JCMDIFrames.
Figure 39 : A maximized internal frame-the iconify and close buttons have moved to the menu bar.
Figure 40 : One frame is maximized. The Iconify, Maximize, and Close buttons appear on the menu bar.
10.2 Properties
For a full listing of these components' properties, see Properties of JCMDIFrame and Properties of JCMDIPane, in Appendix A.
JCMDIFrame
has the same properties asJInternalFrame
.Along with the properties inherited from
JDesktopPane
, there are two additional properties inJCMDIPane
:frameManipulationStyle
andconsiderIconsWhenTiling
. SettingframeManipulationStyle
allows you to control how a frame is painted when it is dragged within the desktop. The default style,JCMDIPane.DEFAULT
, causesJCMDIPane
to repaint the entire frame when dragging. The second style, called wireframe, causesJCMDIPane
to repaint a rectangle that matches the size of the frame. The wireframe dragging style is used whenframeManipulationStyle
is set toJCMDIPane.WIREFRAME
. TheconsiderIconsWhenTiling
property controls the way that windows are tiled (false
means that windows will be tiled using the entire desktop area;true
means that windows will not be tiled over any icons that appear on the desktop).
10.3 Methods
Methods of JCMDIFrame
Methods of JCMDIPane
There are a number of protected methods available to application programmers who wish to subclass a
JCMDIPane
. Consult the API for a list of these methods.
10.4 Examples
This code snippet highlights the few things that need to be done to convert your MDI application based on
import com.klg.jclass.swing.JCMDIPane;JInternalFrame
into one based onJCMDIFrame
.
import com.klg.jclass.swing.JCMDIFrame;
/**
* The class extends JClass Elements' JCExitFrame so you don't have to
* write repetitive window closing code.
*/
public class MDIInternalFrameDemo extends JCExitFrame implements
ActionListener {
/**
* The internal frames reside inside a JCMDIPane
*/
public MDIInternalFrameDemo() {
super("JCMDIPane Demo");
...
desktop = new JCMDIPane(); // a custom layered pane
createFrame(); // Create first window
...
}
/**
* Each frame can have its own menu bar, whose elements are
* defined by you. A "Window" menu is added automatically.
*/
protected void createFrame() {
JCMDIFrame iframe = new JCMDIFrame(
"MDI Frame #" + (++MDIFrameCount),
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable
...
/**
* Use this method to set the menu bar on the frame, even though
* it appears on the desktop rather than on the individual frame.
*/
iframe.setMDIMenuBar(mbar);
...
![]() ![]() ![]() |