簡體   English   中英

JFrame布局問題,面板應位於頂部但位於中間

[英]JFrame Layout issue, Panels should be at the top but are in middle

我有兩個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); 

采用:

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

請參閱: 修復對齊問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM