This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Is there any tool to find the location of a componenet in the frame in Swing? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Is there any tool to find the location of a componenet in the frame in Swing?" Watch "Is there any tool to find the location of a componenet in the frame in Swing?" New topic
Author

Is there any tool to find the location of a componenet in the frame in Swing?

Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
Hi,

We have tool to locate each component in a web page. Also we can change the location of component in run-time.
I need a similar tool to locate each component in a frame.

It will be very useful to locate the component, if it not visible in frame.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10426
    
    8

I am not aware of any such tool. I doubt if its more than a few lines of code.

From the top of my head, in pseudo code
1) Get all child components inside a Container(hint)
2) Get the bounds(hint) of each child
3) Use recursion


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
Don't you get the components as an array if you use the right method, so you can recursively traverse that array?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4572
    
    5

Or -
- get the component's location on screen
- get the window ancestor for the component (SwingUtilities method)
- get the window's location on screen
- do the math

luck, db
There are no new questions, but there may be new answers.
 
GeeCON Prague 2014
 
subject: Is there any tool to find the location of a componenet in the frame in Swing?