![]() |
||
![]() |
![]() Alden Hosting provides professional, efficient, and reliable business-class Web hosting services to small- and medium-sized businesses. |
|
|
JAVA, JSP, SERVLETS, TOMCAT, SERVLETS MANAGER, |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
![]() |
| Window decorations provided by the look and feel | Window decorations provided by the window system | Custom icon; window decorations provided by the look and feel |
Here is an example of creating a frame with a custom icon and with window decorations provided by the look and feel:
//Ask for window decorations provided by the look and feel.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create the frame.
JFrame frame = new JFrame("A window");
//Set the frame icon to an image loaded from a file.
frame.setIconImage(new ImageIcon(imgURL).getImage());
As the preceding code snippet implies,
you must invoke the setDefaultLookAndFeelDecorated method
before creating the frame
whose decorations you wish to affect.
The value you set with setDefaultLookAndFeelDecorated
is used for all subsequently created JFrames.
You can switch back to using window system decorations
by invoking JFrame.setDefaultLookAndFeelDecorated(false).
Some look and feels might not support window decorations;
in this case, the window system decorations are used.
The full source code for the application
that creates the frames pictured above is in
FrameDemo2.java.
Besides showing how to choose window decorations,
FrameDemo2 also shows how to disable all window decorations
and gives an example of positioning windows.
It includes two methods that create the Image objects
used as icons —
one is loaded from a file,
and the other is painted from scratch.
Try this::
- Click the Launch button to run the Frame Demo using Java™ Web Start (download JDK 6). Alternatively, to compile and run the example yourself, consult the example index.
![]()
- Bring up two windows, both with look-and-feel-provided decorations, but with different icons.
The Java look and feel displays the icons in its window decorations. Depending on your window system, the icon may be used elsewhere to represent the window, especially when the window is minimized.- Bring up one or more windows with window system decorations.
See if your window system treats these icons differently.- Bring up one or more windows with no window decorations.
Play with the various types of windows to see how the window decorations, window system, and frame icons interact.
By default, when the user closes a frame onscreen, the frame is hidden. Although invisible, the frame still exists and the program can make it visible again. If you want different behavior, then you need to either register a window listener that handles window-closing events, or you need to specify default close behavior using theThe default close operation is executed after any window listeners handle the window-closing event. So, for example, assume that you specify that the default close operation is to dispose of a frame. You also implement a window listener that tests whether the frame is the last one visible and, if so, saves some data and exits the application. Under these conditions, when the user closes a frame, the window listener will be called first. If it does not exit the application, then the default close operation — disposing of the frame — will then be performed.setDefaultCloseOperationmethod. You can even do both.The argument to
setDefaultCloseOperationmust be one of the following values, the first three of which are defined in theWindowConstantsinterface (implemented byJFrame,JInternalPane, andJDialog):
DO_NOTHING_ON_CLOSE- Do not do anything when the user requests that the window close. Instead, the program should probably use a window listener that performs some other action in its
windowClosingmethod.HIDE_ON_CLOSE(the default forJDialogandJFrame)- Hide the window when the user closes it. This removes the window from the screen but leaves it displayable.
DISPOSE_ON_CLOSE(the default forJInternalFrame)- Hide and dispose of the window when the user closes it. This removes the window from the screen and frees up any resources used by it.
EXIT_ON_CLOSE(defined in theJFrameclass)- Exit the application, using
System.exit(0). This is recommended for applications only. If used within an applet, aSecurityExceptionmay be thrown.
Note:DISPOSE_ON_CLOSEcan have results similar toEXIT_ON_CLOSEif only one window is onscreen. More precisely, when the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate. See AWT Threading Issues for details.
For more information about handling window-closing events, see How to Write Window Listeners. Besides handling window-closing events, window listeners can also react to other window state changes, such as iconification and activation.
The following tables list the commonly usedJFrameconstructors and methods. Other methods you might want to call are defined by thejava.awt.Frame,java.awt.Window, andjava.awt.Componentclasses, from whichJFramedescends.Because each
JFrameobject has a root pane, frames have support for interposing input and painting behavior in front of the frame children, placing children on different "layers", and for Swing menu bars. These topics are introduced in Using Top-Level Containers and explained in detail in How to Use Root Panes.The API for using frames falls into these categories:
- Creating and Setting Up a Frame
- Setting the Window Size and Location
- Methods Related to the Root Pane
Creating and Setting Up a Frame Method or Constructor Purpose JFrame()
JFrame(String)Create a frame that is initially invisible. The Stringargument provides a title for the frame. To make the frame visible, invokesetVisible(true)on it.void setDefaultCloseOperation(int)
int getDefaultCloseOperation()Set or get the operation that occurs when the user pushes the close button on this frame. Possible choices are: The first three constants are defined in the
DO_NOTHING_ON_CLOSEHIDE_ON_CLOSEDISPOSE_ON_CLOSEEXIT_ON_CLOSEWindowConstantsinterface, whichJFrameimplements. TheEXIT_ON_CLOSEconstant is defined in theJFrameclass.void setIconImage(Image)
Image getIconImage()
(inFrame)Set or get the icon that represents the frame. Note that the argument is a java.awt.Image object, not a javax.swing.ImageIcon(or any otherjavax.swing.Iconimplementation).void setTitle(String)
String getTitle()
(inFrame)Set or get the frame title. void setUndecorated(boolean)
boolean isUndecorated()
(inFrame)Set or get whether this frame should be decorated. Works only if the frame is not yet displayable (has not been packed or shown). Typically used with full-screen exclusive mode or to enable custom window decorations. static void setDefaultLookAndFeelDecorated(boolean)
static boolean isDefaultLookAndFeelDecorated()Determine whether subsequently created JFrames should have their Window decorations (such as borders, and widgets for closing the window) provided by the current look-and-feel. Note that this is only a hint, as some look and feels may not support this feature.
Setting the Window Size and Location Method Purpose void pack()
(inWindow)Size the window so that all its contents are at or above their preferred sizes. void setSize(int, int)
void setSize(Dimension)
Dimension getSize()
(inComponent)Set or get the total size of the window. The integer arguments to setSizespecify the width and height, respectively.void setBounds(int, int, int, int)
void setBounds(Rectangle)
Rectangle getBounds()
(inComponent)Set or get the size and position of the window. For the integer version of setBounds, the window upper left corner is at the x, y location specified by the first two arguments, and has the width and height specified by the last two arguments.void setLocation(int, int)
Point getLocation()
(inComponent)Set or get the location of the upper left corner of the window. The parameters are the x and y values, respectively. void setLocationRelativeTo(Component)
(inWindow)Position the window so that it is centered over the specified component. If the argument is null, the window is centered onscreen. To properly center the window, you should invoke this method after the window size has been set.
Methods Related to the Root Pane Method Purpose void setContentPane(Container)
Container getContentPane()Set or get the frame content pane. The content pane contains the visible GUI components within the frame. JRootPane createRootPane()
void setRootPane(JRootPane)
JRootPane getRootPane()Create, set, or get the frame root pane. The root pane manages the interior of the frame including the content pane, the glass pane, and so on. void setJMenuBar(JMenuBar)
JMenuBar getJMenuBar()Set or get the frame menu bar to manage a set of menus for the frame. void setGlassPane(Component)
Component getGlassPane()Set or get the frame glass pane. You can use the glass pane to intercept mouse events or paint on top of your program GUI. void setLayeredPane(JLayeredPane)
JLayeredPane getLayeredPane()Set or get the frame layered pane. You can use the frame layered pane to put components on top of or behind other components.
All of the standalone applications in this trail useJFrame. The following table lists a few and tells you where each is discussed.
Example Where Described Notes FrameDemoThe Example Explained Displays a basic frame with one component. FrameDemo2Specifying Window Decorations Lets you create frames with various window decorations. Framework— A study in creating and destroying windows, in implementing a menu bar, and in exiting an application. LayeredPaneDemoHow to Use Layered Panes Illustrates how to use a layered pane (but not the frame layered pane). GlassPaneDemoThe Glass Pane Illustrates the use of a frame glass pane. MenuDemoHow to Use Menus Shows how to put a JMenuBarin aJFrame.
Alden Hosting offers private JVM (Java Virtual Machine), Java Server Pages (JSP), Servlets, and Servlets Manager with our Web Hosting Plans WEB 4 PLAN and WEB 5 PLAN , WEB 6 PLAN .
At Alden Hosting we eat and breathe Java! We are the industry leader in providing affordable, quality and efficient Java web hosting in the shared hosting marketplace. All our sites run on our Java hosing platform configured for optimum performance using Java 1.6, Tomcat 6.0.X, MySQL 5.0.x, Apache 2.2.xx and web application frameworks such as Struts, Hibernate, Cocoon, Ant, etc.
We offer only one type of Java hosting - Private Tomcat. Hosting accounts on the Private Tomcat environment get their very own Tomcat server. You can start and re-start your entire Tomcat server yourself.
![]() |
|
http://alden-servlet-Hosting.com
JSP at alden-servlet-Hosting.com
Servlets at alden-servlet-Hosting.com
Servlet at alden-servlet-Hosting.com
Tomcat at alden-servlet-Hosting.com
MySQL at alden-servlet-Hosting.com
Java at alden-servlet-Hosting.com
sFTP at alden-servlet-Hosting.com
http://alden-tomcat-Hosting.com
JSP at alden-tomcat-Hosting.com
Servlets at alden-tomcat-Hosting.com
Servlet at alden-tomcat-Hosting.com
Tomcat at alden-tomcat-Hosting.com
MySQL at alden-tomcat-Hosting.com
Java at alden-tomcat-Hosting.com
sFTP at alden-tomcat-Hosting.com
http://alden-sftp-Hosting.com
JSP at alden-sftp-Hosting.com
Servlets at alden-sftp-Hosting.com
Servlet at alden-sftp-Hosting.com
Tomcat at alden-sftp-Hosting.com
MySQL at alden-sftp-Hosting.com
Java at alden-sftp-Hosting.com
sFTP at alden-sftp-Hosting.com
http://alden-jsp-Hosting.com
JSP at alden-jsp-Hosting.com
Servlets at alden-jsp-Hosting.com
Servlet at alden-jsp-Hosting.com
Tomcat at alden-jsp-Hosting.com
MySQL at alden-jsp-Hosting.com
Java at alden-jsp-Hosting.com
sFTP at alden-jsp-Hosting.com
http://alden-java-Hosting.com
JSp at alden-java-Hosting.com
Servlets at alden-java-Hosting.com
Servlet at alden-java-Hosting.com
Tomcat at alden-java-Hosting.com
MySQL at alden-java-Hosting.com
Java at alden-java-Hosting.com
sFTP at alden-java-Hosting.com
JSP
Servlets
Tomcat
mysql
Java
JSP
Servlets
Tomcat
mysql
Java
JSP
Servlets
Tomcat
mysql
Java
JSP
Servlets
Tomcat
mysql
Java
JSP at JSP.aldenWEBhosting.com
Servlets at servlets.aldenWEBhosting.com
Tomcat at Tomcat.aldenWEBhosting.com
mysql at mysql.aldenWEBhosting.com
Java at Java.aldenWEBhosting.com
Web Hosts Portal
Web Links
Web Links
Web Hosting
JSP Solutions Web Links
JSP Solutions Web Hosting
Servlets Solutions Web Links
Servlets Solutions Web Hosting
Web Links
Web Links
.
.
.
.
.
.
.
.
.
.
jsp hosting
servlets hosting
web hosting
web sites designed
cheap web hosting
web site hosting
myspace web hosting