6 Ways to Create a JInternalFrame - Example

The following example illustrates 6 ways to create a JInternalFrame easily using its six constructors.
import javax.swing.*;
import java.awt.*;
class JInternalFrameExample extends JFrame
JInternalFrame f1,f2,f3,f4,f5,f6;
JDesktopPane pane;

    public JInternalFrameExample()
    private void createAndShowGUI()
        setTitle("JInternalFrame Example");
        pane=new JDesktopPane();
        // No title,not resizable,not iconifiable,not maximizable, not closable, no icon
        f1=new JInternalFrame();
        // Only title, others same as above
        f2=new JInternalFrame("Internal Frame 2");
        // title and resizable
        f3=new JInternalFrame("Internal Frame 3",true);
        // title, resizable, closable
        f4=new JInternalFrame("Internal Frame 4",true,true);
        // title, resizable, closable, maximizable
        f5=new JInternalFrame("Internal Frame 5",true,true,true);
        // title, resizable, closable, maximizable, iconifiable
        f6=new JInternalFrame("Internal Frame 6",true,true,true,true);
        // Set title for f4
        f4.setTitle("Internal Frame 1");
        // Set sizes
        // Make all visible
        // Add all!
    public static void main(String args[])
        new JInternalFrameExample();

JInternalFrame(String title, boolean resizable, boolean closeable, boolean maximizable, boolean iconifiable): This is the sixth constructor, If you can understand this, you'll understand all the remaining constructors. title represents the title of the internal frame, next is resizable whether the frame can be resized, whether the frame can be closed, whether it can be maximized and iconified. The default values of these is false and there will be no title initially. If any of the parameter is not specified in the constructor, the boolean value is false. We need not add JInternalFrame to JDesktopPane but we generally do it. In this way, we can easily create six JInternalFrames using its constructors.

Three things cannot be long hidden: the sun, the moon, and the truth. - Buddha

Posted by at on

Tags: Swing Components,