How to get the left coordinate of a component in a frame?
807607Oct 2 2006 — edited Oct 2 2006Hello!
I would like to know if there is a way to get the left position of a component relative to the JFrame's left side (that is 0) that it is placed on.
So I'm not looking for a way to get the component's position relative to its parent container, that could be a JPanel or whatever, but relative to the main container that is the JFrame, JDialog or JInternalFrame.
I know that it could be easy if we were using absolute positioning, but most of the time, in Swing, we use relative positioning with layout managers, which can make matters very difficult.
I need to know this because I want to make the left position of a static component that I have in all my frames equals to the left position of the first JTextField that I find in all the frames that inherits from a base frame.
So it would be nice if I know a way to write a code to position the component automatically instead of specifiying it in all descendent frames.
I know I could do that by going throught all the components' getParent() method and calling their getX() method, but I'd like to know if there's an easy solution.
Thank you.
Marcos