You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
837 B
33 lines
837 B
package com.fr.design.editor.editor; |
|
|
|
import java.awt.event.KeyAdapter; |
|
import java.awt.event.KeyEvent; |
|
|
|
/** |
|
* @author xiqiu |
|
* @date 2022/1/10 |
|
* @description 一个简单的非负整数框 |
|
*/ |
|
public class NotNegativeIntegerEditor extends IntegerEditor { |
|
private static final String NEG = "-"; |
|
|
|
public NotNegativeIntegerEditor(int columns) { |
|
this(); |
|
this.setColumns(columns); |
|
} |
|
|
|
public NotNegativeIntegerEditor() { |
|
super(); |
|
this.numberField.addKeyListener(new KeyAdapter() { |
|
|
|
@Override |
|
public void keyReleased(KeyEvent evt) { |
|
char keyChar = evt.getKeyChar(); |
|
if (NEG.equals(keyChar + "")) { |
|
numberField.setText(numberField.getTextValue().replace(NEG, "")); |
|
} |
|
} |
|
}); |
|
} |
|
} |
|
|
|
|