• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access parent JFrame component from its Child frame

 
Abhishek Kaushik
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is generic problem i come across every time but could not get any solutions

Situation is

When you have a Parent JFrame window and Several Child Frame inside the parent Window has toolbar and StatusBar
How you handle the following requirements

1 - Based on logic of any child window how can i show a message in StatusBar which is placed in the parent window.

2 - Can I access method in the parent window via child window objects?

Thanks in advance
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot embed JFrame inside another JFrame. Did you mean JDesktopPane and JInternalFrame instead?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> How to access parent JFrame component from its Child frame

the simple solution to the subject title is to make the 'Child frame/s' JDialog's
and, in the JDialog constructor, pass the 'parent JFrame' as the owner
 
Abhishek Kaushik
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Michael I will try that.

My problem i have created several JInteralFrame to do that. Are there no means by which i can access parent window items through childs
 
Abhishek Kaushik
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yippie...

I found the solution



number of getparent() will depend on hierarchy level of your frames and components this return object reference to Parent JFrame
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. That is not the correct way to do it.

JInternalFrame has a method called getDesktopPane() which returns you the JDesktopPane instance.
JDesktopPane subclasses JComponent.
If you invoke JDesktopPane#getTopLevelAncestor() you will get the reference to the parent JFrame.

Since you did not bother to answer
You cannot embed JFrame inside another JFrame. Did you mean JDesktopPane and JInternalFrame instead?

I am not sure if I should waste any more of my time, trying to help you out in the future.

Best of luck with your coding and have a nice day.
 
Abhishek Kaushik
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much Maneesh,

this will be the right way to do this, please dont take this else, if you read my second post from the top you will find that i have mentioned about JInternalFrame

- No doubt Java Ranch is very proactive community
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:If you invoke JDesktopPane#getTopLevelAncestor() you will get the reference to the parent JFrame.

Hi Maneesh,
Thanks this helped me today! I used like below
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!