JWindow is a part of Java Swing and it can appear on any part of the users desktop. It is different from JFrame in the respect that JWindow does not have a title bar or window management buttons like minimize, maximize, and close, which JFrame has. JWindow can contain several components such as buttons and labels.
Constructor of the class are:
- JWindow() : creates an empty Window without any specified owner
- JWindow(Frame o) :creates an empty Window with a specified frame as its owner
- JWindow(Frame o) : creates an empty Window with a specified frame as its owner
- JWindow(Window o) : creates an empty Window with a specified window as its owner
- JWindow(Window o, GraphicsConfiguration g) : creates an empty window with a specified window as its owner and specified graphics Configuration.
- JWindow(GraphicsConfiguration g) :creates an empty window with a specified Graphics Configuration g.
Commonly used methods
- setLayout(LayoutManager m) : sets the layout of the Window to specified layout manager
- setContentPane(Container c) : sets the ContentPane property of the window
- getContentPane() : get the container which is the ContentPane for this Window
- add(Component c): adds component to the Window
- isVisible(boolean b): sets the visibility of the Window, if value of the boolean is true then visible else invisible
- update(Graphics g) : calls the paint(g) function
- remove(Component c) : removes the component c
- getGraphics() : returns the graphics context of the component.
- getLayeredPane() : returns the layered pane for the window
- setContentPane(Container c) :sets the content pane for the window
- setLayeredPane(JLayeredPane l) : set the layered pane for the window
- setRootPane(JRootPane r) : sets the rootPane for the window
- setTransferHandler(TransferHandler n) : Sets the transferHandler property, which is a mechanism to support transfer of data into this component.
- setRootPaneCheckingEnabled(boolean enabled) : Sets whether calls to add and setLayout are forwarded to the contentPane.
- setRootPane(JRootPane root) :Sets the rootPane property of the window.
- setGlassPane(Component glass) : Sets the glassPane property of the window.
- repaint(long time, int x, int y, int width, int height): Repaints the specified rectangle of this component within time milliseconds.
- remove(Component c): Removes the specified component from the window.
- isRootPaneCheckingEnabled() : Returns whether calls to add and setLayout are forwarded to the contentPane or not .
- getTransferHandler() : returns the transferHandler property.
- getRootPane() : Returns the rootPane object for this window.
- getGlassPane() : Returns the glassPane object for this window.
- createRootPane() : Called by the constructor methods to create the default rootPane.
- addImpl(Component co, Object c, int i) : Adds the specified child Component to the window.
The following programs will illustrate the use of JWindow
1. program to create a simple JWindow
1. program to create a multiple JWindow .( where one window is the owner of the other )
Note : the above programs might nor run in an online compiler please use an offline IDE
- Java Swing | JPanel with examples
- Java Swing | JCheckBox with examples
- Java Swing | JComboBox with examples
- Java Swing | JList with examples
- Java Swing | JSplitPane with Examples
- Java Swing | JSeparator with examples
- Java Swing | JDialog with examples
- Java Swing | Internal Frame with examples
- Java Swing | Popup and PopupFactory with examples
- Java Swing | Translucent and shaped Window in Java
- Java Swing | JProgressBar
- Java Swing | JFileChooser
- Java Swing | JPasswordField
- Java Swing | JPopupMenu
- Java Swing | JTextArea
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.