简体   繁体   English

需要与父面板一起增长的JTextArea

[英]JTextArea that needs to grow with parent panel

I want to make my JTextArea field as big as it can be in current JPanel. 我想让我的JTextArea字段与当前的JPanel一样大。 How to do that? 怎么做?

Now it is like this: 现在它是这样的:

    JPanel statusBar = new StatusBar(project);
    JTextArea outputBox = new JTextArea(1, 50); 
    outputBox.setEditable(true);
    statusBar.add(outputBox);

The default layout manager of JPanel is FlowLayout , which wouldn't let the text area fill the entire available space in the panel. JPanel的默认布局管理器是FlowLayout ,它不会让文本区域填充面板中的整个可用空间。

Using BorderLayout should work well: 使用BorderLayout应该运行良好:

statusBar.setLayout( new BorderLayout() );
JTextArea outputBox = new JTextArea(1, 50); 
outputBox.setEditable(true);
statusBar.add(outputBox, BorderLayout.CENTER);

You need a layout manager on the JPanel. 您需要JPanel上的布局管理器。 If its just the JTextArea contained within it and you need to maximise it you can use a simple GridLayout: 如果它只包含在其中的JTextArea并且您需要最大化它,您可以使用简单的GridLayout:

   statusBar.setLayout(new GridLayout(1,1));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM