How can I control the width of JTextFields in Java Swing?

后端 未结 4 1244
醉酒成梦
醉酒成梦 2021-01-03 20:06

I am trying to have several JTextFields on a single row, but I don\'t want them to have the same width. How can I control the width and make some of them wider than others?

4条回答
  •  花落未央
    2021-01-03 20:50

    // 1. create JTextField
    yourTextField = new JTextField();
    // 2. store default height
    int defaultHeight = yourTextField.getSize().getHeight();
    // 3. set custom width and default height
    yourTextField.setSize(new Dimension(yourWidth, defaultHeight));
    

提交回复
热议问题