GridBagLayout의 위치 지정 문제가 있습니다. 센터 (맨 위)에 레이블을 넣으려고 시도하지만 (내 눈에 보이지 않는 이유로) 코드를 사용하려고합니다. : GridBagLayout을 사용하여 위치 지정
Test라는 레이블이 내 창 상단과 중앙에 있어야합니다. 누군가 나에게이 나쁜 위치에 대한 이유를 설명 할 수 있니?
내 프로그램 :public class Accueil extends JFrame {
private JPanel home = new JPanel();
private GridBagConstraints grille = new GridBagConstraints();
private JLabel title = new JLabel("Test");
public Accueil() {
home.setLayout(new GridLayout());
init_grille();
init_title();
this.add(home);
this.setSize(600,600);
this.setTitle("Test One");
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
private void init_grille() {
grille.fill = GridBagConstraints.BOTH;
grille.weightx = 2;
grille.weighty = 5;
grille.ipady=grille.anchor=GridBagConstraints.CENTER;;
}
private void init_title() {
grille.fill = GridBagConstraints.HORIZONTAL;
grille.gridx = 0;
grille.gridy = 0;
home.add(title,grille);
}
public static void main(String [] args) {
new Accueil();
}
}
GridBagLayout을 사용하지 않고 GridLayout을 사용하고 있습니다. –
GridLayout을 사용하려는 경우 태그를 변경해야합니다. –