Making JLabel size/gap as JCheckBox

后端 未结 2 659
难免孤独
难免孤独 2021-01-25 07:04

Please have a look at the following code

import java.awt.GridLayout;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.swin         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-25 07:26

    You have a GridLayout with four large cells, and you're adding checkboxes and emails to different cells separately. They don't know of each other and are aligned based only on their size, which is different.

    To align each checkbox to each email, add them to the layout with regard to their relationship. The simplest way is to make a GridLayout not 2x2 but (N+1)x2, and then add each checkbox and each email to a separate cell. You can also use GridBagLayout, it doesn't require to know the number of cells in advance.

提交回复
热议问题