TextArea resizing

Discussion in 'Java' started by McMatt, Feb 23, 2007.

  1. McMatt

    McMatt Guest

    Hello,

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

    >In article <>, 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-
    >>

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


    Thanks for any help.

    Matthias
     
    McMatt, Feb 23, 2007
    #1
    1. Advertising

  2. McMatt

    McMatt Guest

    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" <> wrote:
    > Hello,
    >
    > i got the problem described in the quote below but the suggested
    > solution (overriding getMinimumSize()) doesn't work for me.
    >
    > >In article <>, 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-
    > >>

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

    >
    > Thanks for any help.
    >
    > Matthias
     
    McMatt, Feb 23, 2007
    #2
    1. Advertising

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

    >>
    >> 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/
     
    Knute Johnson, Feb 23, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nick
    Replies:
    1
    Views:
    372
    Fernando Rodriguez
    May 1, 2008
  2. Nick
    Replies:
    0
    Views:
    350
  3. Nick
    Replies:
    0
    Views:
    295
  4. Pil (Trustworthy from Experience)

    Resizing a div by resizing its borders

    Pil (Trustworthy from Experience), Apr 18, 2009, in forum: Javascript
    Replies:
    9
    Views:
    355
    Proper
    Apr 21, 2009
  5. Proper
    Replies:
    0
    Views:
    200
    Proper
    Apr 18, 2009
Loading...

Share This Page