Solved

JTextArea resizes if setLineWrap() is set

Posted on 2002-07-30
6
1,106 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
6 Comments
 
LVL 3

Accepted Solution

by:
randyd earned 100 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
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!

 
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

Technology Partners: 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

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

733 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