Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > TextArea resizing

Reply
Thread Tools

TextArea resizing

 
 
McMatt
Guest
Posts: n/a
 
      02-23-2007
Hello,

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

>In article <(E-Mail Removed)>, (E-Mail Removed) says...
>>
>>I have a text area which I place in the center of my frame. When I
>>resize the frame and make the width smaller, the text area does not
>>change size, and parts of the text area, including scroll bars become
>>obscured. How can I prevent this ?
>>
>>-Andrew-
>>(E-Mail Removed)

>
>
>You need to override minimumSize for the text area.


Thanks for any help.

Matthias

 
Reply With Quote
 
 
 
 
McMatt
Guest
Posts: n/a
 
      02-23-2007
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);
}
}
}

On 23 Feb., 16:44, "McMatt" <(E-Mail Removed)> wrote:
> Hello,
>
> i got the problem described in the quote below but the suggested
> solution (overriding getMinimumSize()) doesn't work for me.
>
> >In article <(E-Mail Removed)>, (E-Mail Removed) says...

>
> >>I have a text area which I place in the center of my frame. When I
> >>resize the frame and make the width smaller, the text area does not
> >>change size, and parts of the text area, including scroll bars become
> >>obscured. How can I prevent this ?

>
> >>-Andrew-
> >>(E-Mail Removed)

>
> >You need to override minimumSize for the text area.

>
> Thanks for any help.
>
> Matthias



 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      02-23-2007
McMatt wrote:
> Hello,
>
> i got the problem described in the quote below but the suggested
> solution (overriding getMinimumSize()) doesn't work for me.
>
>> In article <(E-Mail Removed)>, (E-Mail Removed) says...
>>> I have a text area which I place in the center of my frame. When I
>>> resize the frame and make the width smaller, the text area does not
>>> change size, and parts of the text area, including scroll bars become
>>> obscured. How can I prevent this ?
>>>
>>> -Andrew-
>>> (E-Mail Removed)

>>
>> You need to override minimumSize for the text area.

>
> 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.

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Resizing a div by resizing its borders Pil (Trustworthy from Experience) Javascript 9 04-21-2009 07:35 AM
Resizing a div by resizing its borders Proper Javascript 0 04-18-2009 08:02 PM
Resizing of the TextArea on border or scrollbar Nick ASP .Net 1 05-01-2008 10:45 PM
Resizing of the TextArea on border or scrollbar Nick HTML 0 05-01-2008 12:41 PM
Resizing of the TextArea on border or scrollbar Nick HTML 0 05-01-2008 12:40 PM



Advertisments