开发者

How to have a dynamic width for a JTextField?

开发者 https://www.devze.com 2023-03-13 20:10 出处:网络
I have a JFrame with a JTextField.I want to g开发者_StackOverflowet the width of the JTextFieldincreased/decreased accordingly when the JFrame is maximized/restored.

I have a JFrame with a JTextField. I want to g开发者_StackOverflowet the width of the JTextField increased/decreased accordingly when the JFrame is maximized/restored.

How can I do that?


You need to use a LayoutManager for the parent component which instructs the JTextField to fill up available space.

The default layout manager for a JFrame will do this however. If you simply call frame.add(new JTextField()) and try to resize the window, the text field will fill the available space. You must be putting the JTextField into an intermediate panel which has a different layout manager. You would need to give more context for us to help you with your specific problem.


Set a component listener to the JFrame. It provides some methods to run when the component is resized, moved, hidden or shown. Here is how to do it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号