forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocFilter.java
More file actions
36 lines (32 loc) · 955 Bytes
/
Copy pathDocFilter.java
File metadata and controls
36 lines (32 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import javax.swing.*;
import javax.swing.text.*;
public class DocFilter
{
public static void main( String[] args ) throws Exception
{
JTextField field = new JTextField(30);
((AbstractDocument)(field.getDocument())).setDocumentFilter(
new DocumentFilter()
{
public void insertString(
FilterBypass fb, int offset, String string, AttributeSet attr)
throws BadLocationException
{
System.out.println("insert");
fb.insertString( offset, string.toUpperCase(), attr );
}
public void replace(
FilterBypass fb, int offset, int length, String string,
AttributeSet attr) throws BadLocationException
{
System.out.println("replace");
fb.replace( offset, length, string.toUpperCase(), attr );
}
} );
JFrame frame = new JFrame("User Information");
frame.getContentPane().add( field );
frame.pack();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setVisible(true);
}
}