常用介绍:

常用组件:

上图所示代码段(自动生成的)
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.JTextPane;
import javax.swing.DefaultComboBoxModel;
public class x1 {
private JFrame frame;
private JTextField textField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
x1 window = new x1();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public x1() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 876, 631);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JLabel lblNewLabel = new JLabel("\u6807\u7B7E");
lblNewLabel.setBounds(165, 112, 54, 31);
frame.getContentPane().add(lblNewLabel);
textField = new JTextField();
textField.setText("\u6587\u672C\u6846");
textField.setBounds(240, 112, 139, 31);
frame.getContentPane().add(textField);
textField.setColumns(10);
JComboBox comboBox = new JComboBox();
comboBox.setModel(new DefaultComboBoxModel(new String[] {"\u4E0B\u62C9\u6846"}));
comboBox.setBounds(165, 169, 157, 36);
frame.getContentPane().add(comboBox);
JButton btnNewButton = new JButton("\u6309\u94AE");
btnNewButton.setBounds(165, 226, 93, 36);
frame.getContentPane().add(btnNewButton);
JTextPane textPane = new JTextPane();
textPane.setText("\u6587\u672C\u57DF");
textPane.setBounds(165, 286, 334, 123);
frame.getContentPane().add(textPane);
}
}
文本框为单行!
文本域可多行!
界面制作步骤:
1.调整界面大小
2.给定面板布局方式
3.加入组件
4.左下角可切换到代码(Source)

去使用windowbuilder制作一个简单的窗口吧!!!
这篇博客介绍了如何利用Java Swing库构建一个简单的图形用户界面(GUI),包括设置窗口大小、添加组件如文本框、组合框、按钮和文本区域,并展示了界面布局的初步设定。通过示例代码,展示了创建和显示GUI的基本步骤。
&spm=1001.2101.3001.5002&articleId=125499569&d=1&t=3&u=d5cad6b6ab3a4a12aee77ddd92c78a5a)
6103

被折叠的 条评论
为什么被折叠?



