By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,034 Members | 819 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,034 IT Pros & Developers. It's quick & easy.

TextArea expands on own?

P: n/a
Hey im kinda a newbie to java so i dont know much any help would be
appreciated. Thanx in advance to anyone who does help or takes the time
to read this.
Hey i have placed a text area in a panel which uses a borderlayout.
the code goes relatively like this

// Create a new JPanel to sit in the top right corner
this.topRight = new JPanel();
this.topRight.setLayout(new BorderLayout());

String plantInfo = plantGetInformation();
plantInformation.setMaximumSize(new Dimension(100, 300));
plantInformation.setText(plantInfo);

private String plantGetInformation()
{
String allInfo = "";
allInfo = allInfo + "Description: " + dataPlant.getDescription() +
"\n";
allInfo = allInfo + "Other Notes: " + dataPlant.getOtherNotes() + "\n";
return allInfo;
}

Anyway my problem is that when I add this information to the text field
the text field expands opff the screen to fit in the text.. The get
description returns a rather long string. Is there anyway i can have
stay at a set size and drop down automatically without using \n?

Thanx

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Merlin_1102 wrote:
Hey im kinda a newbie to java so i dont know much any help would be
appreciated. Thanx in advance to anyone who does help or takes the
time to read this.
Hey i have placed a text area in a panel which uses a borderlayout.
the code goes relatively like this

// Create a new JPanel to sit in the top right corner
this.topRight = new JPanel();
this.topRight.setLayout(new BorderLayout());

String plantInfo = plantGetInformation();
plantInformation.setMaximumSize(new Dimension(100, 300));
plantInformation.setText(plantInfo);

private String plantGetInformation()
{
String allInfo = "";
allInfo = allInfo + "Description: " +
dataPlant.getDescription() +
"\n";
allInfo = allInfo + "Other Notes: " + dataPlant.getOtherNotes()
+ "\n";
return allInfo;
}

Anyway my problem is that when I add this information to the text
field the text field expands opff the screen to fit in the text..
The get description returns a rather long string. Is there anyway i
can have stay at a set size and drop down automatically without
using \n?

Thanx


Hi,
As far as I can tell, your "plantInformation" is a JTextArea. If this
is so, it will indeed get as large as necessary to hold all the text.
If you want a "classic"-style text area, you need a JScrollPane. You
should be able to do the following, wherever it is you have
<something>.add(plantInformation):

JScrollPane sp = new JScrollPane(plantInformation);
<something>.add(sp);

The default configuration is for the JScrollPane to take up the amount
of space it's "supposed" to (i.e. the layout manager, or you, tell it
to - you'll need to call setMaximumSize() on the JScrollPane instead
of the JTextArea), and display scrollbars if the content gets too
big. You can use the 3-parameter constructor or the
set{Vertical|Horizontal}ScrollbarPolicy() methods if you need the
scrollbars to be permanent or nonexistent.

- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/ymUMwxczzJRavJYRAlTRAKCdj876PUgr6PeX8Ai+Z8JiIokKjA CgiaNg
9rWShSX782wgUvj9bidLEEg=
=s3tp
-----END PGP SIGNATURE-----
Jul 17 '05 #2

P: n/a
>
JScrollPane sp = new JScrollPane(plantInformation);
<something>.add(sp);


Additionally if you want to keep the info on screen...

plantInformation.setLineWrap( true );

// and optionally to keep from wrapping in the middle of a word.

plantInformation.setWrapStyleWord( true );
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.