无论我如何为 JLabel 设置边界,它总是在同一个位置。我正在使用 Window Builder Swing Designer 应用程序窗口。这是我的代码:
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
public class Restaurants {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Restaurants window = new Restaurants();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Restaurants() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(0, 0, 1368, 689);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new LineBorder(new Color(0, 0, 0), 12));
panel.setBounds(10, 143, 572, 258);
frame.getContentPane().add(panel);
JLabel label= new JLabel("Chicken Burger Meal");
label.setFont(new Font("Tahoma", Font.PLAIN, 18));
label.setBounds(21,70,173,29);
panel.add(label);
JLabel lblChickenBurger = new JLabel("Chicken Burger");
lblChickenBurger.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblChickenBurger.setBounds(21,22,173,29);
panel.add(lblChickenBurger);
JPanel panel_1 = new JPanel();
panel_1.setBorder(new LineBorder(new Color(0, 0, 0), 12));
panel_1.setBounds(592, 143, 401, 259);
frame.getContentPane().add(panel_1);
JPanel panel_2=new JPanel();
panel_2.setBorder(new LineBorder(new Color(0,0,0), 12));
panel_2.setBounds(10,412,572,228);
frame.getContentPane().add(panel_2);
JPanel panel_3=new JPanel();
panel_3.setBorder(new LineBorder(new Color(0,0,0),12));
panel_3.setBounds(592,411,401,228);
frame.getContentPane().add(panel_3);
JPanel panel_4 = new JPanel();
panel_4.setBorder(new LineBorder(new Color(0, 0, 0), 12));
panel_4.setBounds(1003, 174, 401, 465);
frame.getContentPane().add(panel_4);
JLabel lblNewLabel = new JLabel("Loan Management System");
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 60));
lblNewLabel.setBounds(160, 49, 849, 96);
frame.getContentPane().add(lblNewLabel);
}
}
你觉得哪里不对?我已经整理了我能想到的所有可能的策略,但似乎没有一个策略能产生任何类型的可行解决方案。