Internal Frames in Java Swing


I was learning Swing and I tried the following example from a book.

// File 1
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test2 extends Frame implements ActionListener {
   JButton openButton;
   JLayeredPane desktop;
   JInternalFrame internalFrame;
   public Test2() {
      super("Internal Frame Test");
      openButton = new JButton("Open");
      Panel p = new Panel();
      add(p, BorderLayout.SOUTH);
      addWindowListener(new BasicWindowMonitor());
      desktop = new JDesktopPane();
      add(desktop, BorderLayout.CENTER);
public void actionPerformed(ActionEvent e) {
   if ((internalFrame == null) || (internalFrame.isClosed())) {
      try {
         internalFrame = new JInternalFrame("Internal Frame",false,false,false, true);
         internalFrame.setBounds(50, 50, 200, 100);
         desktop.add(internalFrame, new Integer(1));
   catch(Exception xxx)
public static void main(String args[]) {
   Test2 sif = new Test2();

// File 2
import java.awt.event.*;
import java.awt.Window;

public class BasicWindowMonitor extends WindowAdapter {
     public void windowClosing(WindowEvent e) {
          Window w = e.getWindow();

The files are compiled and executed successfully.
As written in the program when I clicke the "Open" button it should open an internal frame but it is not opening any internal frames.

I have j2sdk1.4.2 and JRE 1.4.2 installed
Processor AMD Athelon XP
OS Windows XP

Any idea about this??
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mayank SAssociate Director - Product EngineeringCommented:
>> desktop.add(internalFrame, new Integer(1));

Try calling desktop.revalidate () after that.
no1nincompoopAuthor Commented:
hi mayankeagle,

Thanks atleast I got a comment from you in this big group...
I tried what you said  ? it didn't work :-)

Mayank SAssociate Director - Product EngineeringCommented:
How about just a call to this.repaint () or this.revalidate () after that?
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

no1nincompoopAuthor Commented:

got the solution.. Please close this question....
Answer is  to add  internalFrame.setVisible(true); in the actionPerformed event after setting the boundary for the internal frame..

This site was a bit useful...

Mayank SAssociate Director - Product EngineeringCommented:
Oh yes, didn't notice that you weren't calling setVisible () sorry :) it has to be called for every top-level container that you wanna display.
no1nincompoopAuthor Commented:
hi cud anyone pls close this question.
PAQed with points refunded (150)

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.