-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFocusTextField.java
executable file
·32 lines (29 loc) · 1.02 KB
/
FocusTextField.java
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
// FocusTextField.java is a simple class to allow automatically selecting
// the contents of a TextField when it gets the focus.
//-----------------------------------------------------------------------
import java.awt.event.FocusListener;
import java.awt.event.FocusEvent;
import javax.swing.JTextField;
class FocusTextField extends JTextField implements FocusListener
{
// constructor to request focus events
//------------------------------------
FocusTextField(int columns)
{
super(columns);
addFocusListener(this);
}
// method to select the entire contents of the text field when the focus
// is gained
//----------------------------------------------------------------------
public void focusGained(FocusEvent e)
{
selectAll();
}
// method to unselect the contents of the text field when the focus is lost
//-------------------------------------------------------------------------
public void focusLost(FocusEvent e)
{
select(0,0);
}
}