File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the handle of focused window

 
Susmitha Metlapalli
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider making Test2 modal. Easiest way of making modal dialog is using JOtionPane#showXXXDialog()
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to Use Code Tags in the future.
 
Susmitha Metlapalli
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic