How do you change the width and height of a JTextField
and a JPasswordField
? I Googled it, but I can't find anything. Thanks for your time!
Asked
Active
Viewed 911 times
1

Andrew Thompson
- 168,117
- 40
- 217
- 433

InfiniTech
- 13
- 1
- 2
- 6
-
Hint: setMinimumSize(), setPreferredSize(), setMaximumSize(). Also, learn to use Google. – Kayaman Oct 18 '13 at 14:17
-
@Kayaman I agree with the advice offered in the 2nd sentence, but unfortunately it often leads to advice as summed up in the 1st sentence, with which I strongly disagree(1). See [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/q/7229226/418556) for the reasons why. 1) Except for a very small number of corner cases that don't apply here. – Andrew Thompson Oct 18 '13 at 14:25
-
@Kayaman I know how to use Google thank you very much, but I prefer a direct answer. – InfiniTech Oct 18 '13 at 14:35
-
2I gave a direct answer (even if Andrew deems it wrong), and I gave helpful advice on using search engines. I dislike the idea that you can just walk up here, ask a trivial question and learn to be spoonfed the correct answers. It will bite you in the backside later on when you'll need to use your own brain to figure something out. Edit: I see from your profile that you're quite young, so I apologize for being harsh. It's just that a lot of the questions here are answered much faster with 5 minutes of Googling, yet people often can't even manage to do that... – Kayaman Oct 18 '13 at 14:37
-
@Kayaman I never said it was *wrong* as such, it is just a sub-optimal way to specify the sizes of GUI components. The 'strong disagreement' was about using those methods in this (or indeed most) cases. OTOH I do feel the comment was clear and specific, and that a comment does not need to contain an answer (since that is what 'answers' are for). – Andrew Thompson Oct 18 '13 at 15:39
1 Answers
3
To adjust the height, set a different font size.
To adjust the width, specify the number of columns during construction. Setting a different font size will also affect the width.

Andrew Thompson
- 168,117
- 40
- 217
- 433