• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get the handle of focused window

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider making Test2 modal. Easiest way of making modal dialog is using JOtionPane#showXXXDialog()
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to Use Code Tags in the future.
 
Susmitha Metlapalli
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Recommended reading
http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
 
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic