• 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 access parent JFrame component from its Child frame

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
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
You cannot embed JFrame inside another JFrame. Did you mean JDesktopPane and JInternalFrame instead?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic