How to get x and y position of JPane in JPanel
I have a JEditorPane in a JPanel. I want to know how far from the left and the right the JEditorPane is from the edge of the JPanel (or the frame as they are the same).
Is there a way to do this?
The Reason Is: I want to put a gradient on the JEditorPane that aligns to the edge of the JPanel in stead of the JEditorPane. The reason I want to do this is because the开发者_如何学Pythonre is a gradient on the JPanel and I don't want the JEditorPane background to appear to cover up the gradient. I would set the background to transparent but I got screen paint issues that I was unable to resolve.
Just call getLocation
on your JEditorPane
. The location of a Component
is relative to its parent.
精彩评论