Adrian Adamczyk
Adrian Adamczyk

Reputation: 3070

JTextArea that needs to grow with parent panel

I want to make my JTextArea field as big as it can be in current 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);

Upvotes: 3

Views: 5459

Answers (2)

anon
anon

Reputation:

The default layout manager of JPanel is FlowLayout, which wouldn't let the text area fill the entire available space in the panel.

Using BorderLayout should work well:

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

Upvotes: 5

AntonyM
AntonyM

Reputation: 1604

You need a layout manager on the JPanel. If its just the JTextArea contained within it and you need to maximise it you can use a simple GridLayout:

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

Upvotes: 4

Related Questions