Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_java thread: Need info about AttributeSet interface


Message #1 by "Hassan Ansari" <misbah_ansari@y...> on Fri, 7 Feb 2003 03:27:08
Hi all,
i have to use LimitedStyledDocument class( i.e. given below) to restrict 
number of characters in my Jtextbox that i have put on a applet.I just 
want to know how to call function "insertString(int offs, String str, 
AttributeSet a)" coz i m a confused about its third parameter 
"AttributeSet a".I sutdied about this AttributeSet interface but could not 
understand much as i m new to java.Now i just want to know what to give 
for third parameter to restrict the numbers of characters in my JTextbox 
and how i will use this function even i do not know how i will use it with 
LimitedStyledDocument's object.It will clear more. 
       
       LimitedStyledDocument's object.It will clear more.
       LimitedStyledDocument  object = new LimitedStyledDocument(4);
       object.insertString(0,JTextbox.getText,???);

??? are my problem what to give for third parameter even if i am using it 
with LimitedStyledDocument's class object.Ayn help would be aprreciated.
Thanks,
Misbah H. Ansari.


 class LimitedStyledDocument extends DefaultStyledDocument {
                int maxCharacters;

                public LimitedStyledDocument(int maxChars) {
                    maxCharacters = maxChars;
                }

                public void insertString(int offs, String str, 
AttributeSet a)
                    throws BadLocationException {
                    //This rejects the entire insertion if it would make
                    //the contents too long. Another option would be
                    //to truncate the inserted string so the contents
                    //would be exactly maxCharacters in length.
                    if ((getLength() + str.length()) <= maxCharacters)
                        super.insertString(offs, str, a);
                    else
                        Toolkit.getDefaultToolkit().beep();
                }
            }

  Return to Index