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.
精彩评论