Solved

Internalframes getting focus

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

Technology Partners: 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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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:

695 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