2012-11-21 3 views
1

왼쪽 상단 모서리에 있어야했던 JPanel이 두 개 있습니다.하지만 어떤 이유인지 그들은 y 축 아래로 절반입니다 (그러나 여전히 왼쪽이므로 0 x 축에서). 어쨌든 여기에 내 코드를 게시 할 것이므로 내 문제를 더 쉽게 이해할 수 있다고 생각합니다. 모든 도움을 미리 감사드립니다.JFrame 레이아웃 문제, 패널 상단에 있어야하지만 중간에 있습니다

JFrame scrabbleBoard = new JFrame();        
    scrabbleBoard.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  

    Container topPane = scrabbleBoard.getContentPane();    
    topPane.setLayout(new BoxLayout(topPane, BoxLayout.X_AXIS)); 

    JButton done = new JButton ("Done");        
    JLabel player1 = new JLabel ("Player 1"); 

    topPane.add(player1);   
    topPane.add(done);   

    scrabbleBoard.pack(); 
    scrabbleBoard.setVisible(true); 

답변

4

사용 :

done.setAlignmentY(Component.TOP_ALIGNMENT); 
player1.setAlignmentY(Component.TOP_ALIGNMENT); 

참조 : Fixing Alignment Problems

+0

미안 제대로 설명하지 않았다. 내가 원하는 것은 글자 그대로 "PANEL1 PANEL2"와 같은 두 개의 패널에 대한 것입니다. Y_AXIS를 사용하는 경우에는 서로 위에 얹어 놓은 것처럼 ... 의미가 있습니까? – Dave

+0

구성 요소 맞춤 설정은 트릭을 수행해야합니다 – Reimeus

+0

@Dave Reimueus 제안을 시도 했습니까? –