This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to get the handle of focused window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to get the handle of focused window" Watch "How to get the handle of focused window" New topic
Author

How to get the handle of focused window

Susmitha Metlapalli
Ranch Hand

Joined: May 16, 2007
Posts: 44
Hi,

How to get handle of focus window/jdialog/jframe?

/*Test.java*/


import java.awt.*;

public class Test
{
public static void main(String args[])
{
Test1 t1 = new Test1();
t1.show();
}
}

/*Test1.java*/

import javax.swing.JDialog;
import java.awt.event.*;
import java.awt.*;

public class Test1 extends JDialog
{
public Test1()
{
setTitle("Test1");
setSize(500,300);

Component comp = this;

addWindowListener(new WindowAdapter()
{
public void windowOpened(WindowEvent e)
{
Test2 t2= new Test2();
t2.show();
}
});
}
}


/*Test2.java*/

import javax.swing.JDialog;

public class Test2 extends JDialog
{
public Test2()
{
setTitle("Test2");
setSize(300,200);
}
}

Now, i want to get the handle of focus window.

In the above example, focus window will be Test2. How to know what is focused window from Test.java?

Thanks,
Susmitha.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10172
    
    8

Consider making Test2 modal. Easiest way of making modal dialog is using JOtionPane#showXXXDialog()


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

You might want to Use Code Tags in the future.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Susmitha Metlapalli
Ranch Hand

Joined: May 16, 2007
Posts: 44
Hi,

I am working on a product which has its only framework developed in swings.

There is a java class which has a JPanel. JPanel invokes a JDialog based on some conditions.

JDialog is private. I cannot modify the existing java class. I can only extend it.

How can i get the handle for that JDialog from this extended class? Please help me to proceed further.

Thanks in advance,
Susmitha.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10172
    
    8

Recommended reading
http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get the handle of focused window
 
Similar Threads
I am getting clone() has protected access in java.lang.Object
Code within a curly braces
Webcam & Threads
could someone help?
Focus problem with setModal in JDialog