Nov 8, 2009

Few Questions About Jtextarea

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General > Java

Few Questions About Jtextarea

NewGuyinTown
There are a few things I want to ask:
1.) I want to know if there is a way to stop the JTextArea from expanding as the user types text into it.
I want the TextArea's width locked.
2.) I want to get each line (or row) of text the user typed in after the sumbit button is hit separately from the whole string of the TextArea. I have not tested out the getText() method, but I'm pretty sure it will return a string of the whole TextArea.
3.) Set a maximum characters per line (4)

Thank you,
Simon Tang.

Comment/Reply (w/o sign-up)

snutz411
QUOTE(NewGuyinTown @ Feb 15 2006, 08:14 PM) *

There are a few things I want to ask:
1.) I want to know if there is a way to stop the JTextArea from expanding as the user types text into it.
I want the TextArea's width locked.
2.) I want to get each line (or row) of text the user typed in after the sumbit button is hit separately from the whole string of the TextArea. I have not tested out the getText() method, but I'm pretty sure it will return a string of the whole TextArea.
3.) Set a maximum characters per line (4)

Thank you,
Simon Tang.



1. You should be able to set width. textarea1.setWidth(some number);

2. I don't think you can get just a row in the text area, since getText() will return the entire string. But you can break up the giant string into the rows by some simple string manipulation. You'll probably want to find an escape key such as "\n" in the string which would be the same as a return character. If you need help on the stringl manipuation then post again.

3. Hmmm, the only way I can think of would be to have some error checking function after you hit submit. Which would count the number of characters in the whole text area. Taking what you have from my answer in #2 this should be pretty easy.

if (row1.length >= 4)
{
//pop up box to indicate warning
}

 

 

 


Comment/Reply (w/o sign-up)

Jack Cheng
If you want to limit what the user types into the TextArea, you might want to set up a Document listener on the textarea. As such, whenever the user modifies the contents of the textarea, you can perform some type of validation on the content. An example of DocumentListener implementation follows:

public class docListener implements javax.swing.event.DocumentListener {

public void insertUpdate(DocumentEvent evt) {
validate(evt);
}

public void removeUpdate(DocumentEvent evt) {
validate(evt);
}

public void changedUpdate(DocumentEvent evt) {
validate(evt);
}

// extra methods
public void validate(DocumentEvent evt) {
if (evt.getLength()>=4) {
// alert user
}
}
}

Comment/Reply (w/o sign-up)

Jof33z
CODE
if (JTextarena.length >= 40) // # is based on characters
{
gui.newJlabel("Stop"); // lol dont use a JLabel but use something that will popup
}

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Questions Jtextarea


    Looking for questions, jtextarea

See Also,

*SIMILAR VIDEOS*
Searching Video's for questions, jtextarea
advertisement



Few Questions About Jtextarea

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com