Solved

Internalframes getting focus

Posted on 1998-08-27
3
186 Views
Last Modified: 2011-09-20
Hi there,

I'm using swing, and have a desktop pane with 4 internal frames. What I want to do is to detect when one of the
window gets the focus. I tried adding focuslisteners to
each of the internal frames, but it doesn't seem to be
detecting it. Also, the title bar doesn't seem to detect
any mouse events. Any ideas? Thanks in advanced.
0
Comment
Question by:zyca
  • 2
3 Comments
 
LVL 1

Expert Comment

by:satishb
ID: 1222762

Hi Mr. Zyca,

You can try using an InternalFrameListener for this purpose. The method InternalFrameActivated(InternalFrameEvent e) will catch such events. Then you can go through the InternalFrame in a desktop and can find  wich frame it is.

All the best
Satish.
0
 

Author Comment

by:zyca
ID: 1222763
I need some actual code on how this can be done
0
 
LVL 1

Accepted Solution

by:
satishb earned 50 total points
ID: 1222764

Hi zyca,

Here is the code which i am using for such purpose and it is perfectly working. Ofcourse i am providing just the skeleton.


THis is in your InternalFrame class.

public class InternalFrameWindow extends JInternalFrame {

    /** The Desktop object */
    private Desktop theDesktop;
   
    public InternalFrameWindow (Desktop parent,......) {

    ..................

    this.addInternalFrameListener(new InternalFrameAdapter() {
            public void internalFrameActivated (InternalFrameEvent e) {
                theDesktop.setActiveWindow(InternalFrameWindow.this);
            }
    });
  .................
  .............
  }

Then where ever you want to find our the internal frame that got activated you need to go through the internal frames in that desktop and find out which one has the focus.

           JInternalFrame[] openFrames = desktop.getAllFrames();

            for(int x = 0; x < openFrames.length; x++)
            {
             
                if (openFrames[x] instanceof   whateveryourinternalframeclassis )
                {
                      if (openFrames[x].isSelected()) {
                          do something
                      }
                }
            }

I hope this works for you. Let me know if you need any more information.

good luck
satish.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mapAB Challlenge 35 126
reasons why a "inside Menu" would not appear for a web server 6 56
Java Server Faces parameter pass? 6 39
tomcat administrtor 12 29
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

896 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now