Get location of a swing component

前端 未结 6 1244
野的像风
野的像风 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:01

    Please tell me how to get the Y position of each Jpanel from the JPanel container JPanel.

    • BoxLayout accepting XxxSize (Preferred in this case) that returns its child,

    • JPanel returns (0, 0) this is correct value

    • this or simlair result you can get from all LayoutManager, for example built_in FlowLayout for JPanel (accepting only the PreferredSize), returns the same coordinates (0, 0)

    • excepting BorderLayout then is there generated 10pixels(for W, E, N, S areas), and valid only in the case that CENTER area is used for some JComponent

    • JPanel is Container and by empty JPanel by defualt returns zero size on the screen,

    • JPanel can to returns proper coordinates if is there any JComponent or you override XxxSize in the JPanel constructor

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题