TextArea resizing

M

McMatt

Hello,

i got the problem described in the quote below but the suggested
solution (overriding getMinimumSize()) doesn't work for me.
You need to override minimumSize for the text area.

Thanks for any help.

Matthias
 
M

McMatt

Here is just a small SSCCE:

import java.awt.*;
import javax.swing.*;

public class TextAreaInScrollpane
{
static JPanel mPanel = new JPanel();
static JScrollPane mScrollPane;

public static void main(String[] args)
{
mPanel = new JPanel(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
constraints.weighty = 1.0;

mScrollPane = new JScrollPane(mPanel);

JTextArea ta = new SpecialTextArea();
ta.setLineWrap(true);
ta.setText("Hallo, mein Name is Theodor. Hallo, mein Name is
Theodor. Hallo, mein Name is Theodor. Hallo, mein Name is Theodor.
Hallo, mein Name is Theodor. Hallo, mein Name is Theodor. Hallo, mein
Name is Theodor. Hallo, mein Name is Theodor. Hallo, mein Name is
Theodor. Hallo, mein Name is Theodor. Hallo, mein Name is Theodor. ");
mPanel.add(ta, constraints);

JFrame frame = new JFrame();
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
frame.setContentPane( mScrollPane );
frame.pack();
frame.setVisible(true);
}

@SuppressWarnings("serial")
private static class SpecialTextArea extends JTextArea
{
public SpecialTextArea()
{
super("");
super.setEditable(false);
super.setLineWrap(true);
super.setWrapStyleWord(true);
}

public Dimension getMinimumSize()
{
return new Dimension(1,1);
}
}
}

Hello,

i got the problem described in the quote below but the suggested
solution (overriding getMinimumSize()) doesn't work for me.
 
K

Knute Johnson

McMatt said:
Hello,

i got the problem described in the quote below but the suggested
solution (overriding getMinimumSize()) doesn't work for me.


Thanks for any help.

Matthias

The text area isn't going to get smaller if it is in a scroll pane. The
frame will but that's the scroll pane's job to make the underlying
components still fit. You do have some other problems though when you
make the frame bigger because you have GridBagConstraints.fill set to
BOTH it makes the text area larger. You have a conundrum going on. Use
a different layout manager or set the preferred size of the text area
and turn off the fill or take it out of the scroll pane or ... There
are too many options to give you without knowing exactly what you want
to do in the end.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top