I found that JTextFields can be manipulated easily with acm functions such as setLocation(), as in:

    textfield.setLocation(x,y);

However I cannot seem to be able to find a method that can set the default size of a JTextField. I tried using setPreferedSize() but it didn't change the size of the JTextField.

Any help would be fantastic.

有帮助吗?

解决方案

I cannot seem to be able to find a method that can set the default size of a JTextField.

I don't know that the ACM library has any special methods to do this. I would just look at the API for the JTextField:

JTextField textField = new JTextField(10);

Will make the text field larger enough to hold a minimum of 10 characters.

I found that JTextFields can be manipulated easily with acm functions such as setLocation()

Not sure what the ACM functions are, but you should not be using methods like setLocation(). That is the job of the layout manager to set the location of a component based on the rules of the layout manager that you are using.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top