[英]How do i use border layouts?
我目前正在研究 Java 布局。 我正在嘗試結合不同的布局。 所以我使用 Spring Layout、GridLayout 和 Border Layout 創建了一個登錄屏幕。 MainFrame (JFrame) 使用 GridLayout。 GridLayout 由 2 個面板(北面板和主面板)組成。 主面板由 Jlabel、JTextfield 和 JButton 組成,我對此沒有任何問題。 我的問題是在使用邊框布局的北面板中。 它包含一個 JLabel (lblWelcome)。 我一直在嘗試使用邊框布局將標簽帶到面板的中心,但它仍然向左對齊。 這是下面的代碼:
JLabel lblWelcome = new JLabel("Welcome To The Login Screen");
JPanel northPanel = new JPanel(new BorderLayout());
northPanel.setBackground(Color.green);
northPanel.add(lblWelcome, BorderLayout.CENTER);
登錄屏幕:
您的JLabel
實際上正確居中,但它的文本不是。
只需將其創建更改為:
JLabel lblWelcome = new JLabel("Welcome To The Login Screen", SwingConstants.CENTER);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.