Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Internalframes getting focus

Posted on 1998-08-27
3
Medium Priority
?
195 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 100 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

971 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