Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Internal Frames in Java Swing

Posted on 2006-04-23
8
Medium Priority
?
380 Views
Last Modified: 2013-11-23
hi

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");
      setSize(500,400);
      openButton = new JButton("Open");
      Panel p = new Panel();
      p.add(openButton);
      add(p, BorderLayout.SOUTH);
      addWindowListener(new BasicWindowMonitor());
      openButton.addActionListener(this);
      desktop = new JDesktopPane();
      desktop.setOpaque(true);
      add(desktop, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e) {
   System.out.println("TEST1");
   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)
   {
      System.out.println("Exception"+xxx);
   }
   System.out.println("TEST");
   }
}
public static void main(String args[]) {
   Test2 sif = new Test2();
   sif.setVisible(true);
}
}


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

public class BasicWindowMonitor extends WindowAdapter {
     public void windowClosing(WindowEvent e) {
          Window w = e.getWindow();
          w.setVisible(false);
          w.dispose();
          System.exit(0);
     }  
}

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??
0
Comment
Question by:no1nincompoop
  • 3
  • 3
7 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 16518873
>> desktop.add(internalFrame, new Integer(1));

Try calling desktop.revalidate () after that.
0
 

Author Comment

by:no1nincompoop
ID: 16526985
hi mayankeagle,

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

Regards
Muke
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16527248
How about just a call to this.repaint () or this.revalidate () after that?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:no1nincompoop
ID: 16527267
hi

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...
http://java.sun.com/developer/JDCTechTips/2001/tt1220.html

Regards
Muke
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16527301
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.
0
 

Author Comment

by:no1nincompoop
ID: 16561125
hi cud anyone pls close this question.
0
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16778464
PAQed with points refunded (150)

GranMod
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Don’ts and Dos are two important end products of software testing basics that a tester needs to regard. This article attempts to explain the principles of both.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question