Solved

JTextArea resizes if setLineWrap() is set

Posted on 2002-07-30
6
1,089 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now