0
Java에서 간단한 프로그램을 만들려고합니다. 그 중 가장 아래쪽에 이 있고 그 바로 아래에 JButton
이 있어야합니다. BoxLayout
을 사용한 다음 FlowLayout
을 시도했지만 프로그램 시작시 JLabels
이 사라집니다. button
을 클릭하면 모든 것이 올바르게 표시되지만 수동으로 창 크기를 조정해야합니다. 누군가 제가 잘못하고있는 것을 설명 할 수 있습니까? 감사!Java GUI 레이아웃 관련 문제
public class ProgramUI {
private JButton _jbutton;
private ArrayList<JLabel> _jlabels;
private JFrame _jframe;
private JPanel _top, _bottom;
public ProgramUI(){
_jframe = new JFrame();
_jframe.getContentPane().setLayout(new BoxLayout(_jframe.getContentPane(), BoxLayout.Y_AXIS));
_top = new JPanel();
_jframe.add(_top);
_bottom = new JPanel();
_jframe.add(_bottom);
_top.setLayout(new FlowLayout(FlowLayout.LEFT));
_bottom.setLayout(new FlowLayout(FlowLayout.LEFT));
_jlabels = new ArrayList<JLabel>();
for (int i=0; i<8; i++) {
JLabel label = new JLabel();
_jlabels.add(label);
_top.add(label);
//...rest of code is not relevant
}
_jbutton = new JButton();
_bottom.add(_jbutton);
_jframe.pack();
_jframe.setVisible(true);
_jframe.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}