Why aren't my components wrapping in Swing's FlowLayout?

前端 未结 2 1743
走了就别回头了
走了就别回头了 2021-01-25 19:23

Why aren\'t my components wrapping in this JPanel using FlowLayout? They simply run off screen and are only partially visible.

JPanel panel = new JPanel(new Flo         


        
2条回答
  •  -上瘾入骨i
    2021-01-25 19:59

    I know this is an old question, but I stumbled upon it while trying to solve the same problem. It is not entirely true that FlowLayout will not wrap its child components.

    The issue is that the JPanel with your desired FlowLayout must be inside another container that will resize and allow the FlowLayout to also resize and therefore wrap. In my experience, the CENTER region of a BorderLayout is the only such container that will allow this to happen.

提交回复
热议问题