Get location of a swing component

前端 未结 6 1239
野的像风
野的像风 2021-01-18 03:19

I have put some JPanels into another JPanel which its\' layout is Box Layout and Y-Axis. After I have put all the panels I need to get the Y position of each added JPanel in

6条回答
  •  星月不相逢
    2021-01-18 04:08

    Coordinates are relative to their parent. In your exemple, all the child components are being added along the top of the parent container, making there y position 0 (relative to their parent).

    Try adding an empty border to the parent container, you should see the y position change.

    You can use the SwingUtilities.convertPoint to convert between coordinate systems

提交回复
热议问题