Dynamically growing JPanel with BoxLayout (on a null layout)

后端 未结 4 1561
灰色年华
灰色年华 2021-01-16 18:38

I have a JPanel with a vertical BoxLayout on top of a JPanel with a null layout.

I would like the JPanel with the BoxLayout to grow as the components are being added

4条回答
  •  隐瞒了意图╮
    2021-01-16 19:11

    Suggestions:

    • Don't use null layout, almost ever.
    • Why not give the total JPanel a BorderLayout?
    • Then add the BoxLayout using JPanel to the BorderLayout.NORTH (or also known as BorderLayout.PAGE_START) position.

    Edit
    You state,

    IN ADVANCE: I need the position of "box" to be at exactly 100,200 so please do not suggest that I do not use null layout. I must use null layout. The null layout of "total" should not effect the answer to my question, which focuses on the "box" panel.

    I think that you are once again putting needless restrictions on your program. You can place your "box" at 100, 200 easily by putting an empty border of that size around it, or by other means. But the answer is not to throw out use of the null layout.

提交回复
热议问题