?
Solved

JTextArea resizes if setLineWrap() is set

Posted on 2002-07-30
6
Medium Priority
?
1,118 Views
Last Modified: 2011-09-20
Wonder if someone could help me folks....

I have a JTextArea control that is inside a JScrollPane.  The JScrollPane control is inside a GridBagLayout panel.

What I want the control to support is word and line wrapping so I've set both properties as follows:

myTextArea.setLineWrap(true);
myTextArea.setWrapStyleWorld(true);

The problem I have is when the app is run, the JTextArea control quickly resizes itself just after its displayed.  This is annoying and something that I cannot have happen.

The constraints I've set and are required for the JSrollPane are:

GridBagConstraints.BOTH

Can someone help?  Thanks.
0
Comment
Question by:carlpaddick
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Accepted Solution

by:
randyd earned 400 total points
ID: 7188807
you can mess with the layout manager and/or set the max size and preferred size of the component.

for instance, try to set the max size and see what happens when the grid bag compoenent is resized.  then set the gridbag to borderlayout and see the difference.

randy
0
 
LVL 92

Expert Comment

by:objects
ID: 7189313
Put your scrollpane in a borderlayout instead of gbl.
0
 
LVL 9

Expert Comment

by:yongsing
ID: 7189477
Put the JTextArea in a JPanel:

JPanel panel = new JPanel();
panel.add(myTextArea);

Then put the JPanel in the JScrollPane:

JScrollPane scrollPane = new JScrollPane(panel);

And finally add the JScrollPane to the panel which has a GridBagLayout.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 26

Expert Comment

by:ksivananth
ID: 7189759
Try by setting only the following,

    JTextArea textArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane( taNotes, JScrollPane.VERTICAL_SCROLLBAR_ASNEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );

textArea..setLineWrap( true );
scrollPane.setPreferredSize( new Dimension( 100, 70 ) );
0
 

Author Comment

by:carlpaddick
ID: 7190081
Guys,

Thanks for all your answers. Apologies for the delay with the reply.  I'm ahead of your time zones and had gone home from work yesterday.  I'm on leave today and tomorrow so when I get back on Friday, I'll try some of your suggestions out and let you know what works.

Thanks once again
0
 

Author Comment

by:carlpaddick
ID: 7196108
Randyd was the first to answer the question and his answer works perfectly:

myTextAreaScrollPane.setPreferredSize(new Dimension(x,y));

I therefore award him the points but my thanks go to the rest of you guys for helping.  You're all really helping my knowledge with Java language.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question