NewGuyinTown 0 Report post Posted February 16, 2006 (edited) 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. Edited February 16, 2006 by miCRoSCoPiC^eaRthLinG (see edit history) Share this post Link to post Share on other sites
snutz411 0 Report post Posted February 16, 2006 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} Share this post Link to post Share on other sites
Jack Cheng 0 Report post Posted February 18, 2006 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 } } } Share this post Link to post Share on other sites
Jof33z 0 Report post Posted June 1, 2006 if (JTextarena.length >= 40) // # is based on characters{gui.newJlabel("Stop"); // lol dont use a JLabel but use something that will popup} Share this post Link to post Share on other sites