To limit number of chracters in textarea.

hello all,
please find below a small program to demonstrate how to limit number of charcaters in a textarea.
i searchedthe forum and i actually got the technique from the forum. but when i put together a sa program it does not work.
could anyone point out what is the problem in the small piece of code below.
i am working on jdk 1.2.1
thanx to all.
// Example illustrating Limiting number of characters in text area.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class try1 extends JApplet {
Container contentPane;
JLabel label;
JTA1 textarea;
public void init() {
// Get the handle on the applet's content pane.
     contentPane = this.getContentPane();
// Create a text field and add a key listener to it.
     textarea = new JTA1(25);           // of 25 char width
// Create a button object and register an action listener
     Button button = new Button("Clear");
     button.addActionListener(new ButtonListener());
// Create a label with the titled border.
     label = new JLabel("Key Typed: NiL");
     label.setBorder(BorderFactory.createTitledBorder
("You pressed the Following Key"));
// Add the text field and button to the applet's content pane.
     contentPane.setLayout(new BorderLayout());
     contentPane.add("North", textarea);
     contentPane.add(label);
     contentPane.add("South", button);
// Get focus on text field.Note: You can do this only after you add the text field to the container
class ButtonListener implements ActionListener {     // Create the button listener class.
     public void actionPerformed(ActionEvent e)      {
// Reset the text components
     textarea.setText("");
//Return the focus to the text field.
class JTA1 extends JTextArea
     private int limit;
     public JTA1 ( int limit )
          this.limit = limit;
          addKeyListener( new LimitListener() );     
     class LimitListener extends KeyAdapter
          public void keyPressed( KeyEvent ke )
               if( getText().trim().length() >= limit )
               {     ke.consume(); //just consume KeyEvent

Don't cross post. This question has been answered in your other post.

Similar Messages

  • How to limit number of logins per day?

    We have a custom web application (WebAS 6.20) used by people and automated systems. Each user has his own login, and some of these automated systems sometimes produce heavy load because they log into system too often.
    Is there an easy way to:
    1) limit number of logins to, say, 1000 per day and when this limit is reached - do not allow this user to login till midnight
    OR
    2) dedicate one of the processes to the specific user
    thanks in advance

    extend PlainDocument class to restrict the number of characters per line.
    Set this class as model to TextArea.
    Below is a class which does this. May be its useful
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    public class FixedNumericDocument extends PlainDocument {
    private int maxLength = 9999;
    private String max="";
    public FixedNumericDocument(int maxLength) {
    super();
    this.maxLength = maxLength;
    //this is where we'll control all input to our document.
    //If the text that is being entered passes our criteria, then we'll just call
    //super.insertString(...)
    public void insertString(int offset, String str, AttributeSet attr)
    throws BadLocationException {
    if (getLength() + str.length() > maxLength) {
    return;
    else {
    try {
    //check if str is numeric only
    int value = Integer.parseInt(str);
    //if we get here then str contains only numbers
    //chk if it is less than 65535 so that it can be inserted
    super.insertString(offset, str, attr);
    catch(NumberFormatException exp) {
    return;
    return;

  • Limit Number of Rows on a Page

    Hi all,
    I am unable to succeed with the following.
    I have an XML data source which looks like this:
    <?xml version="1.0"?>
    <LIST_GEMPLOYEES>
    <LIST_G_EMPLOYEE>
    <EMPLOYEE_NUMBER>1</EMPLOYEE_NUMBER>
    <EMPLOYEE_NAME>Employee 1</EMPLOYEE_NAME>
    </LIST_G_EMPLOYEE>
    <LIST_G_EMPLOYEE>
    <EMPLOYEE_NUMBER>2</EMPLOYEE_NUMBER>
    <EMPLOYEE_NAME>Employee 2</EMPLOYEE_NAME>
    </LIST_G_EMPLOYEE>
    <!-- many rows here (LIST_G_EMPLOYEE tags) -->
    </LIST_GEMPLOYEES>
    And I want to define a template which only allows 5 rows on a page.
    What I did:
    I should insert a page break after the limit number of rows on a page is reached. This means that, after each group of 5 rows, a page break should be inserted.
    To accomplish this goal, I followed these steps:
    1. Define a field which will contain and initialize the Counter variable before the table which will show the list of employees, by using the syntax:
    Field1: <?xdoxslt:set_variable($_XDOCTX, ’Counter’, 0)?>
    2. Define the table which list all employees in the data source:
    2.1. Use a 2 columns table. In the first column, define 2 fields as follows:
    2.2. In the second column, define 6 fields containing the following code:
    Field2: <?for-each: LIST_G_EMPLOYEE?>
    Field3: <?EMPLOYEE_NUMBER?>
    Field4: <?xdoxslt:set_variable($_XDOCTX, ’Counter’, xdoxslt: get_variable($_XDOCTX, ’Counter’) + 1)?>
    Field5: <?EMPLOYEE_NAME?>
    Field6: <?if: xdoxslt:get_variable($_XDOCTX, ’Counter’) mod 5=0?>
    Field7: <?split-by-page-break:?>
    Field8: <?end if?>
    Field9: <?end for-each?>
    Here is explanation for syntax I used:
    Field1: Declare and init Counter variable to value = 0
    Field2: This fetches through all employees - start a for-each cycle
    Field3: This prints the employee number
    Field4: This increments the Counter variable
    Field5: This prints the employee name
    Field6: This tests whether Counter variable is divided by 5
    Field7: This generates a page break
    Field8: End of condition
    Field9: End of for-each cycle
    Result:
    The first page has just the header and the second page has the header and only record and it goes the same
    for the rest of the pages. Any help is greatly appreciated.
    Thanks.

    Have a look at this post
    http://winrichman.blogspot.com/2008/09/limit-row-per-page.html

  • Limit number of concurrent connection

    is there a way for me to limit the number of concurrent
    connections to the media server. my upload bandwitdh is about a meg
    so having too many connections just kills the whole thing. i would
    like to put a limit at 5 connections. is there a way to do
    this?

    well i am only using flash media server to displaying videos
    and just that. the reason i went with media server vs. progressive
    was fullscreen method. since flash doesn't natively support
    fullscreen you have to open another browser in fullscreen with
    javascript. the problem with that is it start loading from
    beginning so i decided to go server that way it only has to buffer
    and get to the same point without having to load the whole video up
    to that point. Now i want to limit number people that can be
    watching the video. if i get more that 5 connection the whole thing
    slows down. i am not too familiar with server based connections so
    i don't know how to limit the number concurrent connections.

  • Limit number for new field

    Hello there
    Anybody know what is the limit number for new field in each record type?
    My client wants me to create about 200 new fields in Account record type.
    Is it possible to do so?

    Hi, You can refer this
    https://secure-ausomxdsa.crmondemand.com/docs/1.10.0.1080.0.00/enu/help/CustomFieldHelp.html
    -- Venky CRMIT

  • Limit number of recipients send out external once

    Hi all,
    I have Exchange server 2013 CU7, I want to limit number of recipients when my users send email to external/internet.
    For example:
    If my users send email to more than 50 external recipients once, they will receive error "bla bla"
    Limitation is not apply when my users send email to internal recipients"
    or external sender send email to internal recipients
    How can I do it ? (which send connector , receive connector , transport config , transport service , transport server)
    Thank for your help.
    Jack

    Hi Jack,
    Thank you for your question.
    I agree with Bruce.
    I am sorry that we could not meet your requirement that the limit of recipient is just for external/Internet.
    When we configure those setting, it will be worked for all recipient(including internal or external). It was referred by the following link:
    https://technet.microsoft.com/en-us/library/bb310760%28v=exchg.141%29.aspx
    If there are any questions regarding this issue, please be free to let me know. 
    Best Regard,
    Jim
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]
    Jim Xu
    TechNet Community Support

  • Limit number of subfolders

    Hi Experts,
    Is there a way to limit number of subfolders created on a InfoView folder?
    We want out application to limit external admin users not to create more than 3 level of subfolders in InfoView Folder.
    Please advice
    Thanks!
    Prasath

    Not from within InfoView or the CMC.  You would have to write your own InfoView replacement that would handle this limitation.
    -Dell

  • Limit number of loans

    Hi
    I have a returnable loan with maximum 3. A client downloads 3 differents acsm files (Makes 3 clicks on my button to download) and, after, he open they width ADE.  Now he has three identical copies and there is no freedom for the rest. Yes we are bugging.
    How i can avoid it? We can tell to ACS that a user can only have a maximum of 3 books on loan?
    Ty

    The loan limit number is the number of simultaenous users that can have the file loaned out.   By default the user can read the content on any device that that they have activated (limited roughly to 6 computers and 6 devices).   If this is not what you desire, you can limit the user to the single device that they first download the content on, by adding a <device/> element into the permissions.
    ACS4 provides no way to provide more than a single device, but less than all the devices the user has activated.

  • How can I limit the number of ros in TextArea?

    As I turn on the line wrap and having used setRows method,
    I cannot limit the number of rows of the textarea into 2.
    How can I limit it?
    Thanks.

    camickr wrote:
    I give up. You don't know specify requirements and I'm not going to prompt you every 5 minutes for more information.
    due to setText method So this implies that the text comes from somewhere, maybe a database, but the user does not type the text directly into the text area.
    If you define the text area with 2 rows, then the third row will not be visible, so I don't see the problem. Just don't add the text area to a scroll pane and the user will never know the third row is there.[http://i188.photobucket.com/albums/z55/nwoedf/temp/error.png ]
    it demonstrates the problem with excess line
    The third row is still visible even I have used setRow(2).

  • Limit number of character in a TextArea

    Hi,
    how can I limited the number of character in a jTextArea?
    thanks!

    You have to customize the Document that your text area is using. You can read more about the Document interface here:
    http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/text/Document.html
    And here is a simple example that demonstrates how you can customize a Document to do what you want. The program should compile and run as is. It will display a JTextArea that only allows ten characters.
    import javax.swing.*;
    import javax.swing.text.*;
    public class LimitedTextArea extends JFrame {
        public LimitedTextArea() {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            JTextArea text = new JTextArea(5, 40);
            // Set the customized Document on the text area. Only allow
            // a maximum of ten characters:
            text.setDocument(new LimitedDocument(10));
            getContentPane().add(new JScrollPane( text ));
            pack();
            setLocationRelativeTo(null);
        public static void main(String[] args) {
            new LimitedTextArea().setVisible(true);
        // Document that only allows a certain number of characters
        class LimitedDocument extends PlainDocument {
            private int maxLength;
            public LimitedDocument(int maxLength) {
                this.maxLength = maxLength;
            // This method is overriden from the super class. It will be called when
            // you are trying to insert text in your text component (by typing
            // or pasting).
            public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
                int currentLength = getLength();
                if( currentLength >= maxLength ) {
                    // There's not room for more characters. Return.
                    return;
                if( currentLength + str.length() > maxLength ) {
                    // All of the characters we are trying to insert will not fit.
                    // We must trim the string.
                    str = str.substring(0, maxLength - currentLength);
                // Insert the text:
                super.insertString(offs, str, a);
    }

  • APEX Supplied HTML Editor (fckeditor) - Limit number of characters

    Hi
    Has anyone found a way of limiting the number of characters allowed in the HTML Editor that is supplied with APEX (3.1/fckeditor)
    I have had a look at the fckeditor web page and found a couple of plugins but I fear that this approach will require me to manually implement fckeditor, and not use the inbuilt one.
    I would also prefer to not do this with an application process as the user can overflow the editor and get the HTTP-400 Value param too long error.
    Regards
    Matt

    Dribble!
    does this help? Is their anyway to limit the character count on a textarea with html editor

  • Can you limit the size of a TextArea?

    I've developed a program which logs what it does into a file as well as into a TextArea component. We've just realised a potential problem though in that this program may be left running several weeks at a time and the TextArea could become very full and tie up a lot of memory.
    So basically I need a good solution for limiting its size. I thought that each time it could clear itself and read through the log file for, say, the last 50 events but that process may also start taking a long time if the log file gets big too.
    Any solutions?
    Both the file logging and textarea logging are handled by a seperate class. There is one log() method which accepts a string and takes care of both.

    Its easily done on a JTextArea. Basically every time the text area is updated you check the number of lines in the text area and remove any lines above your limit.

  • Limit number of chars per line

    Hi ,
    how to limit the number of chars per Line in a textArea or RTFEditableText?
    I have to do the following:
    Allow 25 Chars for first line,
    any other line should have max. 28 chars.
    First line should have a bold font.
    Not an easy thing..
    I tried to use a textarea fpr input and put the text into a datagrid in the textarea.change() event.
    This works, but I lose a lot of the standard features of the textarea (hyphenation etc.)
    The idea is to use only the textarea or a RTFEditor for applying the rules mentioned above.
    Thanks
    thorsten

    extend PlainDocument class to restrict the number of characters per line.
    Set this class as model to TextArea.
    Below is a class which does this. May be its useful
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    public class FixedNumericDocument extends PlainDocument {
    private int maxLength = 9999;
    private String max="";
    public FixedNumericDocument(int maxLength) {
    super();
    this.maxLength = maxLength;
    //this is where we'll control all input to our document.
    //If the text that is being entered passes our criteria, then we'll just call
    //super.insertString(...)
    public void insertString(int offset, String str, AttributeSet attr)
    throws BadLocationException {
    if (getLength() + str.length() > maxLength) {
    return;
    else {
    try {
    //check if str is numeric only
    int value = Integer.parseInt(str);
    //if we get here then str contains only numbers
    //chk if it is less than 65535 so that it can be inserted
    super.insertString(offset, str, attr);
    catch(NumberFormatException exp) {
    return;
    return;

  • How to limit number of mail messages on iPhone with iOS7?

    Is there a way to limit the number of inbox email messages showing?  On iOS6, it was in Settings under Mail but this option is not there on iOS7  Is it hiding somewhere else?  If this isn't an option at all, are there any suggestions on a work around?  Without it, a lot of memory is being wasted.  Thanks!

    No, this is no longer an option.
    You can let Apple know about your displeasure (as many have) by leaving them feedback here:  www.apple.com/feedback http://www.apple.com/feedback

  • How to limit number of sessions for an Application

    Hi,
    I have an ASO application running on Essbase 7.1.5 version.
    This Essbase cube is widely used by the BO ( business objects ) Web I services for retrieving data in there Dash Boards.
    No I want to restrict number of sessions on this application. We have SERVERTHREADS through which we can set limit on application wise.
    SERVERTHREADS [application] 20;
    When I set this in the Essbase config file on this server and bounce the Essbase services. Will this really help me in limiting the session till 20 for this application . I see we can set minimum 20 and maximum 500 using server threads.
    What will happen to the session which excceds 20. will they be kept in queue ?.
    Pls let me know if this work. Else pls suggest me the best one.
    Some information for you – in the Essbase ->properties->statistics-> I see Ports Available are 65531
    Thanks
    MS

    HI,
    1. SERVERTHREADS does not contain/limit the count of sessions one can have .
    2. Count of ports will help you decide what is the default SERVERTHREAD count , in your case its 20.
    3. the count 20 signifies the number of threads which a transaction can use ( here threads are nothing by the operating system level threads, to do with the processes and processor).
    4. If you have multiple transactions and you want to improve the performance of them ( in case of slow response or so). You can increase the thread count , to make more threads work for your transactions. Again , this does not limit the count of sessions .
    5. I did not understand the obejctive behind limiting the sessions and avoiding users from accessing . I think , this defeats the whole purpose of having cubes then. You have many cubes ,and huge number of users who pull data and essbase and its kernel are capable of handling this . If you still want to restrcit, might as well set their security ( by letting them not to access cubes).
    Hope this adds value
    Sandeep Reddy Enti
    HCC
    http://hyperionconsultancy.com/

Maybe you are looking for

  • Booting issue on a new installation on Acer Aspire 4752 laptop.

    Hi All,      I have done a new installation of OS on a Acer laptop stated above.  However, due to some reason, during the booting up process, it will always stuck at screen right before it enter into the logon screen. I will have to press Enter in or

  • Enhanced forecaster is not compatible with Firefox 3.6 or 4.0. What can I do? I realy like that feature.

    Enhanced forecaster does not work with my current firefox 3.6 I can go to help and hit repair/extensions and it works for a while. When you go to add ons, it says it is not compatible with 3.6. I downloaded 4.0 and it's the same way. It does not work

  • Approve Working Time

    Dear All I have a requirement. When an employee books time in the section "Record Working Time", it goe for approval in "Approve Time sheet data" in MSS under Work Overview>Team>Employee Working Times>Approve Time sheet data. Now my client needs that

  • How to Configure SOA db connection

    Hi Firends, I successfully installed SOA on linux using the 10g DB. Then later I installed 11g Database on another Oracle_Home. How do I configure SOA so that it will connect to my 11g DB instead of the 10g DB? Thanks a lot

  • PDF thumbnail generation has stopped working

    Hello Together, formerly I was using Adobe Reader X at an actual Patch Level on a 64 Bit Windows 7 system. At that time PDF thumbnails were no subject for me. Now I've upgraded to Adobe Acrobat X Pro and uninstalled Adobe Reader X. Then I wanted to u