How to make JTextArea Stick to the window

北城以北 提交于 2019-12-01 20:52:26

Use BorderLayout for you gora panel. Put text area to the center:

gora.setLayout(new BorderLayout());
gora.add(jt1, BorderLayout.CENTER);
Andrew Thompson
// declare a GridLayout in constructor, one component will 'fill the container'
JPanel gora = new JPanel(new GridLayout());
JPanel dol = new JPanel();
// this should be called after all components are added!  BNI
pack();
JTextArea jt1 = new JTextArea("JF1");

// be sure to use a scroll pane for multi-line text components
gora.add(new JScrollPane(jt1));
// ..

Stretching a single component to fill the available space can be achieved various was. Two common ways are using either BorderLayout as mentioned by AlexR or GridLayout. See this answer for sample code. I prefer GridLayout because it is shorter (less typing). ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!