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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| public class MultipleSelectionNumber_simple {
// [... code exécutable ...]
/**
* Tester class...
*/
public static class Tester implements DocumentListener {
public void init() {
JFrame frame = new JFrame("Demo - MultipleSelection");
JPanel panel = new JPanel();
Box b = Box.createVerticalBox();
// Only to prevent the selection of the formattedTextField
JTextField txtField = new JTextField();
b.add(txtField);
// Example with a JFormattedTextField
DecimalFormat numberFormat = new DecimalFormat();
JFormattedTextField forTxtField = new JFormattedTextField(numberFormat);
forTxtField.setValue(10);
forTxtField.getDocument().addDocumentListener(this);
b.add(forTxtField);
panel.add(b);
frame.add(panel);
frame.pack();
frame.show();
}
public static void main(String[] args) {
Tester t = new Tester();
t.init();
}
public void insertUpdate(DocumentEvent e) {
System.out.println("insertUpdate");
}
public void removeUpdate(DocumentEvent e) {
System.out.println("removeUpdate");
}
public void changedUpdate(DocumentEvent e) {
System.out.println("changedUpdate");
}
}
} |
Partager