我有JTextField的问题,我无法设置其大小。当我运行程序时,它在整个屏幕上显示我的文本字段。我想让JTextField变小。你知道问题在哪里吗? (抱歉我的英语不好)
我的问题是我设置了JTextField的大小,但它不起作用。
public class MyJFrame extends JFrame {
JLabel label;
String Time = "00:34:12.123";
JPanel MainPanel = new JPanel();
JPanel PINPanel = new JPanel();
JPanel MenuPanel = new JPanel();
JPanel CashPanel = new JPanel();
JPanel WaitPanel = new JPanel();
JPanel TimePanel = new JPanel();
JButton Cash = new JButton();
JButton Time1 = new JButton();
JButton ConfirmPIN = new JButton();
JButton ConfirmCash = new JButton();
JButton ConfirmWait = new JButton();
JLabel PIN = new JLabel();
JTextField EnterPIN = new JTextField(1);
CardLayout CL = new CardLayout();
public MyJFrame(){
super();
initUI();
placeComponents();
bindListeners();
}
private void initUI() {
this.setSize(385, 400);
this.setTitle("ITS class");
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setResizable(false);
}
private void placeComponents(){
PINPanel.setLayout(new BorderLayout());
MainPanel.setLayout(CL);
MainPanel.add(PINPanel, "1");
CL.show(MainPanel, "1");
ConfirmPIN.setText("Ok");
ConfirmPIN.setSize(1,1);
ConfirmPIN.setLocation(150,200);
PIN.setText("Please enter your PIN: ");
PIN.setLocation(20,100);
EnterPIN.setLocation(50,100);
EnterPIN.setSize (10, 10);
this.getContentPane().add(MainPanel);
PINPanel.add(ConfirmPIN);
PINPanel.add(PIN);
PINPanel.add(EnterPIN);