Solved

Internalframes getting focus

Posted on 1998-08-27
3
185 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

759 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

24 Experts available now in Live!

Get 1:1 Help Now