我正在尝试将文本字段放在标签旁边。而不是该文本字段位于标签下方并填充一行。我试图给像 JTextfield(10) 这样的列,但这也没有用。这是关于我正在使用的布局吗?
public class guessTheNumber extends JFrame{
private JLabel info, info2, info3;
private JTextField input;
public guessTheNumber(){
super("Guessing Game");
setLayout(new GridLayout(6,3));
info = new JLabel("I have a number between 1 and 1000.",SwingConstants.CENTER);
add(info);
info2 = new JLabel("Can you guess my number?",SwingConstants.CENTER);
add(info2);
info3 = new JLabel("Please enter your first guess:");
add(info3);
input = new JTextField("",10);
add(input);
}
public static void main(String[] args) {
guessTheNumber gtn = new guessTheNumber();
gtn.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gtn.setLocationRelativeTo(null);
gtn.setSize(500, 200);
gtn.setVisible(true);
}
}