Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

TextArea resizing

Thread view: 
McMatt - 23 Feb 2007 15:44 GMT
Hello,

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

>In article <3330A7AC.4...@worldnet.att.net>, mears...@worldnet.att.net 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-
>>mears...@worldnet.att.net
>
>You need to override minimumSize for the text area.

Thanks for any help.

Matthias
McMatt - 23 Feb 2007 16:24 GMT
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,
>
[quoted text clipped - 16 lines]
>
> Matthias
Knute Johnson - 23 Feb 2007 23:16 GMT
> Hello,
>
[quoted text clipped - 15 lines]
>
> 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.

Signature

Knute Johnson
email s/nospam/knute/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.