简体   繁体   English

如何使用边框布局?

[英]How do i use border layouts?

I'm currently working on Layouts in Java.我目前正在研究 Java 布局。 I'm trying to combine different layouts.我正在尝试结合不同的布局。 So i have created a login Screen using Spring Layout, GridLayout and Border Layout.所以我使用 Spring Layout、GridLayout 和 Border Layout 创建了一个登录屏幕。 The MainFrame (JFrame) uses GridLayout. MainFrame (JFrame) 使用 GridLayout。 The GridLayout consists of 2 Panel (North Panel and Main Panel). GridLayout 由 2 个面板(北面板和主面板)组成。 The Main Panel consists of the Jlabel, JTextfield and JButton of which I have no problem of.主面板由 Jlabel、JTextfield 和 JButton 组成,我对此没有任何问题。 My problem is in the North Panel which uses Border Layout.我的问题是在使用边框布局的北面板中。 It contains a JLabel (lblWelcome).它包含一个 JLabel (lblWelcome)。 I have been trying to bring the label to the center of the panel using Border Layout but it still aligns to the left.我一直在尝试使用边框布局将标签带到面板的中心,但它仍然向左对齐。 This is the below code:这是下面的代码:

  JLabel lblWelcome = new JLabel("Welcome To The Login Screen");
  JPanel northPanel = new JPanel(new BorderLayout());
  northPanel.setBackground(Color.green);
  northPanel.add(lblWelcome, BorderLayout.CENTER);

Login Screen :登录屏幕:

在此处输入图片说明

Your JLabel is actually correctly centered, but its text isn't.您的JLabel实际上正确居中,但它的文本不是。

Simply change its creation to :只需将其创建更改为:

JLabel lblWelcome = new JLabel("Welcome To The Login Screen", SwingConstants.CENTER);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何针对不同的内容使用不同的卡片布局? - How do I use different card layouts for varying content? 如何按行制作布局? - How do I make the layouts in rows? 如何在一个屏幕上使用两个相对布局? - How do i make use of two relative layouts on one single screen? 如何在2种布局中使用FirebaseListAdapter - How to use FirebaseListAdapter with 2 layouts AppCompat如何夸大未明确使用AppCompat小部件的布局? - How does AppCompat inflate layouts that do not explicitly use AppCompat widgets? 如何在Android应用程序开发中使通用布局包含在其他布局中,但如何动态更改通用布局内部的属性? - How do I make generic layouts to include in other layouts but change the properties inside the generic layouts dynamically in android app development? 单击按钮后如何切换活动/布局? - How do I switch Activites/Layouts after clicking a button? 如何在没有JPanels和布局的情况下创建有效的GUI - How do I create a working GUI without JPanels and layouts 使用Android FirebaseListAdapter时如何使用两种布局? - How can I use two layouts when using Android FirebaseListAdapter? 我无法弄清楚如何使用java gui / layouts? - I cant figure out how to use java gui / layouts?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM