Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / May 2008

Tip: Looking for answers? Try searching our database.

Document Filtering Question

Thread view: 
Chris - 29 May 2008 02:29 GMT
All,
I am missing something with regard to document filtering. I have
successfully built this app where the text clears (actually gets
replaced with "") everytime a keystoke is entered into my textField.
However, before the replacement with ("") I would like to somehow save
the text that is coming in to the textField (in a String variable
perhaps?).
Anyhow, your expertise would be very much appreciated.

Thank you,
Chris

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DocumentFilter;

public class textAreaExample {

 public static void main(String[] args) {
     clear();

 }
     public static void clear() {
 final JTextField field = new JTextField(30);

   ((AbstractDocument) (field.getDocument())).setDocumentFilter(new
DocumentFilter()
   {

     public void replace(FilterBypass fb, int offset, int length,
String string, AttributeSet attr)
         throws BadLocationException {
       fb.replace(offset, length, "", attr);

     }

   });

   JFrame frame = new JFrame("ALiiS");
   frame.getContentPane().add(field);
   frame.pack();
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setVisible(true);

 }
}
Knute Johnson - 29 May 2008 04:50 GMT
> All,
>  I am missing something with regard to document filtering. I have
[quoted text clipped - 45 lines]
>   }
> }

So maybe I don't really understand, you've got a text field that when
you type characters into the field they disappear but you really want to
save them somewhere?  Is this supposed to be some sort of password field?

Signature

Knute Johnson
email s/knute/nospam/

Chris - 29 May 2008 04:55 GMT
On May 28, 8:50 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
wrote:
> > All,
> >  I am missing something with regard to document filtering. I have
[quoted text clipped - 61 lines]
>
> - Show quoted text -

No, no password field. I'm just trying to be able to type into a
textbox, and then automatically  (1) store the text that was typed and
(2) clear the text.
Knute Johnson - 29 May 2008 05:09 GMT
> On May 28, 8:50 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
> wrote:
[quoted text clipped - 55 lines]
> textbox, and then automatically  (1) store the text that was typed and
> (2) clear the text.

Do you want to do it on every keystroke or just when the user leaves the
text field?

Signature

Knute Johnson
email s/knute/nospam/

Chris - 29 May 2008 05:16 GMT
On May 28, 9:09 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
wrote:
> > On May 28, 8:50 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
> > wrote:
[quoted text clipped - 70 lines]
>
> - Show quoted text -

I'm looking to do it on every keystroke. I tried writing a class
(below) using a text listener, but couldnt find a way to clear the
text after the text was entered. I tried setText(""); but an infinite
loop threw me a road block, hence my current attemp above.
Thank you by the way for your emails...

Chris

import java.awt.*;
import java.awt.event.*;

public class InputListener extends Frame implements TextListener  {

  public InputListener ( String s )   {
     super ( s ) ;

     setLayout ( null ) ;

     TextField t = new TextField (  ) ;
     t.setSize ( 300,300 ) ;
     t.setLocation ( 50,50 ) ;

     add ( t ) ;

     t.addTextListener ( this ) ;

  }

  public void textValueChanged ( TextEvent e )
  {
      TextComponent tc = (TextComponent)e.getSource();
      s = tc.getText();
      System.out.println(s);
      tc.setText(null);
  }

  public String txt()
  {
     return s;

  }

}
Knute Johnson - 29 May 2008 05:29 GMT
This won't handle backspace and there are other issues but this does
what you said you wanted.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test9 {
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame f = new JFrame();
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                JTextField tf = new JTextField(30);
                tf.addKeyListener(new KeyAdapter() {
                    public void keyTyped(KeyEvent ke) {
                        System.out.print(ke.getKeyChar());
                        ke.consume();
                    }
                });

                f.add(tf,BorderLayout.CENTER);
                f.pack();
                f.setVisible(true);
            }
        });
    }
}

What is the actual purpose of this?

Signature

Knute Johnson
email s/knute/nospam/

Chris - 29 May 2008 05:38 GMT
On May 28, 9:29 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
wrote:
> This won't handle backspace and there are other issues but this does
> what you said you wanted.
[quoted text clipped - 38 lines]
>       ------->>>>>>http://www.NewsDemon.com<<<<<<------
> Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

Wow. Yea that does exactly what has been stumping me for a week. I
really cannot thank you enough. This is a small piece of an
application I am writing for an existing financial project Im trying
to build (not for a fee, for my business). If you wouldnt mind
answering one last question, how long have you been writing Java to
put this together so fast (and clean)?
Thank you again very much.

Chris
Knute Johnson - 29 May 2008 05:48 GMT
> On May 28, 9:29 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
> wrote:
[quoted text clipped - 50 lines]
>
> Chris

Off and on since 1.0, a long time.  I do a fair amount of GUI
programming as well as some graphic/animation work.  I've used it long
enough though that I can usually slap something together if I know what
I want to have when I'm done :-).  Hence the probing question.

Signature

Knute Johnson
email s/knute/nospam/

Chris - 29 May 2008 05:51 GMT
On May 28, 9:48 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
wrote:
> > On May 28, 9:29 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
> > wrote:
[quoted text clipped - 67 lines]
>
> - Show quoted text -

Yea, definately seems so!  Hey, thank you again...


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.