我正在制作一个简单的 java swing 程序,但我的组件的大小和位置有问题。我有三个 Jlabels 和三个 JtextFields。jlabels 是重叠的,所以只有我添加的最后一个显示。文本字段显示得非常小。(几乎看起来像行。)此外,所有内容都出现在一行上,我希望每个组件都在自己的行上。
代码:
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class setCustoms {
static JPanel panel = new JPanel();
static JFrame frame2 = new JFrame("Settings");
public static void makeWindow(){
frame2.setVisible(true);
frame2.add(panel);
frame2.setBounds(500, 300, 500, 200);
JLabel app1l = new JLabel("");
JLabel app2l = new JLabel("");
JLabel app3l = new JLabel("");
JLabel site1l = new JLabel("");
JLabel site2l = new JLabel("");
JLabel site3l = new JLabel("");
panel.add(app1l);
app1l.setText("Set Application ONE name and path");
JTextField app1t = new JTextField();
app1t.setBounds(100, 100, 100, 25);
app1t.addActionListener(new Action());
panel.add(app1t);
panel.add(app2l);
app1l.setText("Set Application TWO name and path");
JTextField app2t = new JTextField();
app2t.addActionListener(new Action());
panel.add(app2t);
panel.add(app3l);
app1l.setText("Set Application THREE name and path");
JTextField app3t = new JTextField();
app3t.addActionListener(new Action());
panel.add(app3t);
}
static class Action implements ActionListener{
public void actionPerformed (ActionEvent e){
}
}
}
编辑:虽然我确实有代码为某些项目设置界限,但它不起作用