To display a message in a GUI, I am using a JTextArea defined as:
JTextArea message = new JTextArea(1,1);
To put the desired real data in the JTextArea (and thus display on the
GUI) I use a statement like this:
message.replaceRange(data.freeText, 0,
message.getText().length());
This works fine for the normal situation. But on occasion, the area of
the GUI where this message appears needs to instead display an image;
in which case, I want the contents of this message to be empty.
Otherwise the message displays on top of (or nibbling into) my image.
In an effort to keep the message from displaying, I've tried this:
message.replaceRange("", 0, message.getText().length());
And this:
message.replaceRange("", 0, 1);
And this:
message.setText("");
All of these result in a "blank" message (i.e., there is no text
displayed), but an equivalent empty/blank "footprint" (of the
message) still appears and corrupts the image I'm displaying.
Is there a way to "clear" the contents of my JTextArea so that it
doesn't display anything at all (i.e., no message and no blank
footprint)?
I know I could just refrain from painting the JTextArea at all
(whenever the image is to display), but in my case that's a separate
piece of logic that I'd just soon not mess with.
Any ideas?
hiwa - 22 Apr 2006 10:51 GMT
We may need to see your code, especially its layout related part.
Post a small demo code that is generally compilable, runnable and
could reproduce your problem. See:
http://homepage1.nifty.com/algafield/sscce.html
How about remove(message) or pack() on the container?