java 如何调整 JTextField 的大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2442111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I resize a JTextField?
提问by LockOn
How can I resize a JTextField?
如何调整 JTextField 的大小?
回答by Brian Agnew
If you look at the Javadoc, you'll see that JTextFieldderives from Component, and that has a setSize()method. If you don't have a layout manager then that's of use.
如果您查看 Javadoc,您会看到JTextField派生自Component,并且有一个setSize()方法。如果您没有布局管理器,那么这很有用。
If you dohave a layout manager, then setPreferredSize()/setMinimumSize()/setMaximumSize()is the way to go. See this SO answerfor more details.
如果你这样做有一个布局管理器,则有必要对setPreferredSize()/ setMinimumSize()/setMaximumSize()是要走的路。有关更多详细信息,请参阅此 SO 答案。
回答by John
The jtextfield tutorialtells you about setColumns(), which might be what you want. Otherwise, you might need to learn about how to use layout managers - here's a tutorial.
该JTextField的教程告诉你setColumns(),这可能是你想要的。否则,您可能需要了解如何使用布局管理器 - 这里有一个教程。

