Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1137
  • Last Modified:

JTextArea resizes if setLineWrap() is set

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
carlpaddick
Asked:
carlpaddick
1 Solution
 
randydCommented:
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
 
objectsCommented:
Put your scrollpane in a borderlayout instead of gbl.
0
 
yongsingCommented:
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.

 
ksivananthCommented:
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
 
carlpaddickAuthor Commented:
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
 
carlpaddickAuthor Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now