Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Internalframes getting focus

Posted on 1998-08-27
3
Medium Priority
?
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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 about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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

722 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