1

左上隅にあるはずだった 2 つの JPanel がありますが、何らかの理由でそれらは y 軸の途中にあります (ただし、まだ残っているため、x 軸は 0 です)。とにかくここにコードを投稿します。その方が私の問題を理解しやすいと思います。助けてくれてありがとう。

 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

1 に答える 1

4

使用する:

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

参照:位置合わせの問題の修正

于 2012-11-21T21:26:37.710 に答える