JTextField 无法调整大小

JTextField can't be resized

我是 JFrame、组件等方面的新手,但我正在尝试更改特定文本字段的大小,以便您可以实际看到您放入其中的内容。这是代码:

import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class InterestCalculator extends JFrame{

    private static final long serialVersionUID = 1L;

    JLabel desc = new JLabel("This is a simple interest calculator.\n"
            + " Enter three fields to get the fourth.");
    JLabel inteLabel = new JLabel("\nInterest: ");
    JTextField inte = new JTextField();

    public static void main(String [] args) {
        InterestCalculator comp = new InterestCalculator();
        comp.FrameHandler();
    }

        public void FrameHandler() {

        setSize(500, 500);
        setTitle("Template");
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
        setLayout(new FlowLayout());

        add(desc);
        add(inteLabel);
        add(inte);

        inte.setSize(new Dimension(100,15));

        validate();
    }
}

这是结果:http://i.imgur.com/SoOEMNT.png 那么,我该如何解决这个问题?

JTextField inte = new JTextField();

应设置列数,即:

JTextField inte = new JTextField(10);

另见 Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?(是。)

同样适用于setSize(..)