更新时间:2022-06-24 14:56:00
insert_panel_0.setPreferredSize( new Dimension(width/4, (int) Math.round( hight*0.05)));
问题是您的宽度计算.当您将其除以4时,每个黑色子面板的宽度就是整个父面板的宽度.这会导致两个问题:
The problem is your width calculation. When you divide by 4 the width of each black child panel is the width of the entire parent panel. This causes two problems:
解决方案是改善宽度计算,例如:
The solution is to improve your width calculation for example:
insert_panel_0.setPreferredSize( new Dimension(width/12, (int) Math.round( hight*0.05)));
现在,两个面板将出现在同一行中.
Now the two panels will appear on the same row.
如果要在两个黑色面板之间留出空隙,则还需要:
If you want a gap between the two black panels then you also need:
//panel_2.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
panel_2.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 0));