Window decorations provided by the look and feel The third frame uses Java look and feel window decorations, but has a custom icon. The first uses decorations provided by the window system, which happen to be Microsoft Windows, but could as easily be any other system running the Java platform.The second and third use window decorations provided by the Java look and feel. As you can tell by the appearance of the button in each frame, all three use the Java look and feel. The following snapshots show three frames that are identical except for their window decorations. A typical icon size is 16x16 pixels, but some window systems use other sizes. Most window systems or look and feels also display the icon in the window decorations. If the window system supports minimization, then the icon is used to represent the minimized window. Exactly how this icon is used depends on the window system or look and feel that provides the window decorations. You can also specify that the frame have no window decorations at all, a feature that can be used on its own, or to provide your own decorations, or withīesides specifying who provides the window decorations, you can also specify which icon is used to represent the window. However, you can request that the look-and-feel provide the decorations for a frame. The two usages are equivalent, but we use setVisible(true) for consistency's sake.īy default, window decorations are supplied by the native window system. ![]() Sometimes you might see the show method used instead. Calling setVisible(true) makes the frame appear onscreen.For example, the following code centers a frame onscreen: This example does not set the frame location, but it is easy to do so using either the setLocationRelativeTo or setLocation method. In general, using pack is preferable to calling setSize, since pack leaves the frame layout manager in charge of the frame size, and layout managers are good at adjusting to platform dependencies and other factors that affect component size. An alternative to pack is to establish a frame size explicitly by calling setSize or setBounds (which also sets the frame location). The pack method sizes the frame so that all its contents are at or above their preferred sizes.If you're not already familiar with content panes and how to add components to them, please read Adding Components to the Content Pane.įor frames that have menus, you'd typically add the menu bar to the frame here using the setJMenuBar method. The next bit of code adds a blank label to the frame content pane.See Responding to Window-Closing Events for more information. This behavior is appropriate for this program because the program has only one frame, and closing the frame makes the program useless. The EXIT_ON_CLOSE operation exits the program when your user closes the frame. ![]() Next the code specifies what happens when your user closes the frame.The other frequently used JFrame constructor is the no-argument constructor. ![]() The first line of code creates a frame using a constructor that lets you set the frame title.Create components and put them in the frame.įrame.getContentPane().add(emptyLabel, BorderLayout.CENTER) Optional: What happens when the frame closes?įtDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) The following FrameDemo code shows how to create and set up a frame. Here is a picture of the extremely plain window created by the FrameDemo demonstration application. To make a window that appears within another window, use an internal frame. To make a window that is dependent on another window disappearing when the other window is iconified, for example use a dialog instead of frame. Applications with a GUI usually include at least one frame. JFrame class, is a window that has decorations such as a border, a title, and supports button components that close or iconify the window. Since the border area is included in the overall size of the frame, the border effectively obscures a portion of the frame, constraining the area available for rendering and/or displaying subcomponents to the rectangle which has an upper-left corner location of (insets.left, insets.top), and has a size of width - (insets.left + insets.right) by height - (insets.top + insets.bottom).Ī frame, implemented as an instance of the The dimensions of the border area may be obtained using the getInsets method. The size of the frame includes any area designated for the border. ![]() A Frame is a top-level window with a title and a border.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |