KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > JXFrame


1 /*
2  * $Id: JXFrame.java,v 1.2 2004/09/30 23:22:56 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.swing;
9
10 import java.awt.Component JavaDoc;
11
12 import javax.swing.JFrame JavaDoc;
13 import javax.swing.JRootPane JavaDoc;
14
15 /**
16  * A smarter JFrame specifically used for top level frames for Applications.
17  * This frame uses a JXRootPane.
18  */

19 public class JXFrame extends JFrame JavaDoc {
20
21     public JXFrame() {
22         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
23     }
24
25     public JXFrame(String JavaDoc title) {
26         super(title);
27         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
28     }
29
30     /**
31      * Overloaded to create a JXRootPane.
32      */

33     protected JRootPane JavaDoc createRootPane() {
34         return new JXRootPane();
35     }
36
37     /**
38      * Overloaded to make this public.
39      */

40     public void setRootPane(JRootPane JavaDoc root) {
41         super.setRootPane(root);
42     }
43
44     /**
45      * Add a component to the Frame.
46      */

47     public void addComponent(Component JavaDoc comp) {
48         JXRootPane root = getRootPaneExt();
49         if (root != null) {
50             root.addComponent(comp);
51         }
52         // XXX should probably fire some sort of container event.
53
}
54
55     /**
56      * Removes a component from the frame.
57      */

58     public void removeComponent(Component JavaDoc comp) {
59         JXRootPane root = getRootPaneExt();
60         if (root != null) {
61             root.removeComponent(comp);
62         }
63         // XXX should probably fire some sort of container event.
64
}
65
66     /**
67      * Return the extended root pane. If this frame doesn't contain
68      * an extended root pane the root pane should be accessed with
69      * getRootPane().
70      *
71      * @return the extended root pane or null.
72      */

73     public JXRootPane getRootPaneExt() {
74         if (rootPane instanceof JXRootPane) {
75             return (JXRootPane)rootPane;
76         }
77         return null;
78     }
79
80     /**
81      * Overloaded to pack when visible is true.
82      */

83     public void setVisible(boolean visible) {
84         if (visible) {
85             pack();
86         }
87         super.setVisible(visible);
88     }
89 }
90
91
Popular Tags