• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to getSize of a parent container ?

 
Anh Nguyen
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a JComponent which supposes to paint itself into another Container ( its parent ) at any location that user want to. The problem is I can't get the size of the parent container ( resizable ) so that I can check if the user enter a correct location.
I tried these codes in the child component :

but none of them work. The first line went through, the last 3 lines compiled OK but then gave NullPointerException at run time. And YES, I have to use the child component to paint itself into its parent component.
Please help !!!
------------------
... No one can escape .......
Heavenly Evil Knight
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first line went through, the last 3 lines compiled OK but then gave
NullPointerException at run time.

couls you pl. elaborate on what you mean by "first line went
through
"......not sure I follow you. Sorry!

regds.
- satya
 
Wirianto Djunaidi
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's very likely that you ran those code in the
Root Container itself, like JFrame or JApplet.
Since they are the top container and nothing else hold them,
when you do getParent() -- it will returns null.
-Ryo
 
Anh Nguyen
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"This first line went through" means if I only included the first line then when I compiled and ran, nothing happened ( nor Exceptions ), but what I want is the size of the parent, not which is the parent !
NO, these codes are in the child JComponent, not the container !
By the way, I found out the reason and have already fixed it . Thank you very much for your time anyway :-) ( But it's worth a try so If you have time, please think about it )

------------------
... No one can escape .......
Heavenly Evil Knight
 
Wirianto Djunaidi
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, dont' I feel stupid
I didn't read your post clearly the first time where you did
mention you are using the child component..
So, what did you figure out? I'm curious to know..
-Ryo
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!