Trying to create multiple JLabels, however only one is appearing

后端 未结 4 1216
时光说笑
时光说笑 2021-01-20 02:23

I am trying to create multiple JLabels of the same form and then trying to add them to the same JPanel. However, only one of the JLabels appears and I can\'t figure out why!

4条回答
  •  借酒劲吻你
    2021-01-20 02:40

    BorderLayout specification says

    A border layout lays out a container, arranging and resizing its components to fit in five regions: north, south, east, west, and center. Each region may contain no more than one component, and is identified by a corresponding constant: NORTH, SOUTH, EAST, WEST, and CENTER. When adding a component to a container with a border layout, use one of these five constants,....

    in here

    As you are using the default add method, it adds components to the center of the parent and thus in your case you see only one component being added.

    You can use other layout (i.e. flow or some other) to satisfy your need.

提交回复
热议问题