本文整理了Java中javax.swing.JTextField.setInputVerifier()
方法的一些代码示例,展示了JTextField.setInputVerifier()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextField.setInputVerifier()
方法的具体详情如下:
包路径:javax.swing.JTextField
类名称:JTextField
方法名:setInputVerifier
暂无
代码示例来源:origin: stackoverflow.com
JComboBox combo = new JComboBox();
JTextField tf = (JTextField)(combo.getEditor().getEditorComponent());
tf.setInputVerifier(verifyer);
代码示例来源:origin: stackoverflow.com
final RawData data = new RawData(null, null);
JTextField first = new JTextField(20);
first.setInputVerifier(new BindingVerifier(data, true));
JTextField second = new JTextField(20);
second.setInputVerifier(new BindingVerifier(data, false));
Action commit = new AbstractAction("commit") {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(data);
}
};
JComponent form = new JPanel();
form.add(first);
form.add(second);
form.add(new JButton(commit));
代码示例来源:origin: robo-code/robocode
desiredTpsTextField.getDocument().addDocumentListener(eventHandler);
desiredTpsTextField.setInputVerifier(
new InputVerifier() {
@Override
代码示例来源:origin: chatty/chatty
InputList(String[] data, InputVerifier inputVerifier) {
// List
list = new JList<>(data);
list.addListSelectionListener(this);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane listScroll = new JScrollPane(list);
// Text input
input = new JTextField();
input.setInputVerifier(inputVerifier);
input.addActionListener(this);
input.getDocument().addDocumentListener(this);
setLayout(new BorderLayout());
/*
* Add everything to the panel
*/
add(input, BorderLayout.NORTH);
add(listScroll);
}
代码示例来源:origin: robo-code/robocode
private JTextField getNumberOfRoundsTextField() {
if (numberOfRoundsTextField == null) {
numberOfRoundsTextField = new JTextField(5);
numberOfRoundsTextField.setText("" + battleProperties.getNumRounds());
numberOfRoundsTextField.setInputVerifier(
new InputVerifier() {
@Override
public boolean verify(JComponent input) {
boolean isValid = false;
String text = ((JTextField) input).getText();
if (text != null && text.matches("\\d+")) {
int numRounds = Integer.parseInt(text);
isValid = (numRounds > 0);
}
if (!isValid) {
WindowUtil.messageError(
"'Number of Rounds' must be an integer value > 0.\n" + "Default value is 10.");
numberOfRoundsTextField.setText("" + battleProperties.getNumRounds());
}
return isValid;
}
});
}
return numberOfRoundsTextField;
}
代码示例来源:origin: robo-code/robocode
private JTextField getInactivityTimeTextField() {
if (inactivityTimeTextField == null) {
inactivityTimeTextField = new JTextField(5);
inactivityTimeTextField.setText("" + battleProperties.getInactivityTime());
inactivityTimeTextField.setInputVerifier(
new InputVerifier() {
@Override
public boolean verify(JComponent input) {
boolean isValid = false;
String text = ((JTextField) input).getText();
if (text != null && text.matches("\\d+")) {
int inactivityTime = Integer.parseInt(text);
isValid = (inactivityTime >= 0);
}
if (!isValid) {
WindowUtil.messageError(
"'Inactivity Time' must be an integer value >= 0.\n" + "Default value is 450.");
inactivityTimeTextField.setText("" + battleProperties.getInactivityTime());
}
return isValid;
}
});
}
return inactivityTimeTextField;
}
代码示例来源:origin: robo-code/robocode
private JTextField getSentryBorderSizeTextField() {
if (sentryBorderSizeTextField == null) {
sentryBorderSizeTextField = new JTextField(5);
sentryBorderSizeTextField.setText("" + battleProperties.getSentryBorderSize());
sentryBorderSizeTextField.setInputVerifier(
new InputVerifier() {
@Override
public boolean verify(JComponent input) {
boolean isValid = false;
String text = ((JTextField) input).getText();
if (text != null && text.matches("\\d+")) {
int borderSize = Integer.parseInt(text);
isValid = (borderSize >= 50);
}
if (!isValid) {
WindowUtil.messageError(
"'Sentry Border Size' must be an integer value >= 50.\n" + "Default value is 100.");
sentryBorderSizeTextField.setText("" + battleProperties.getSentryBorderSize());
}
return isValid;
}
});
}
return sentryBorderSizeTextField;
}
代码示例来源:origin: robo-code/robocode
private JTextField getGunCoolingRateTextField() {
if (gunCoolingRateTextField == null) {
gunCoolingRateTextField = new JTextField(5);
gunCoolingRateTextField.setText("" + battleProperties.getGunCoolingRate());
gunCoolingRateTextField.setInputVerifier(
new InputVerifier() {
@Override
public boolean verify(JComponent input) {
boolean isValid = false;
String text = ((JTextField) input).getText();
if (text != null && text.matches("\\d*(\\.\\d+)?")) {
double gunCoolingRate = Double.parseDouble(text);
isValid = (gunCoolingRate > 0 && gunCoolingRate <= 0.7);
}
if (!isValid) {
WindowUtil.messageError(
"'Gun Cooling Rate' must be a floating point number > 0 and <= 0.7.\n"
+ "Default value is 0.1.");
gunCoolingRateTextField.setText("" + battleProperties.getGunCoolingRate());
}
return isValid;
}
});
}
return gunCoolingRateTextField;
}
代码示例来源:origin: org.icepdf.os/icepdf-viewer
public JTextField buildCurrentPageNumberTextField() {
JTextField pageNumberTextField = new JTextField("", 3);
pageNumberTextField.setToolTipText(messageBundle.getString("viewer.toolbar.navigation.current.tooltip"));
pageNumberTextField.setInputVerifier(new PageNumberTextFieldInputVerifier());
/**
* Add a key listener and check to make sure the character intered
* is a digit, period, the back_space or delete keys. If not the
* invalid character is ignored and a system beep is triggered.
*/
pageNumberTextField.addKeyListener(new PageNumberTextFieldKeyListener());
if (viewerController != null)
viewerController.setCurrentPageNumberTextField(pageNumberTextField);
return pageNumberTextField;
}
代码示例来源:origin: stackoverflow.com
textField.setInputVerifier(new InputVerifier() {
代码示例来源:origin: org.icepdf.os/icepdf-viewer
/**
* Utility for building input field that handles page number limits for the
* current document.
*
* @return pageNumber text field with listeners for validation.
*/
private JTextField buildDocumentPageNumbers() {
final JTextField textField = new JTextField();
textField.setInputVerifier(new PageNumberTextFieldInputVerifier());
textField.addKeyListener(new PageNumberTextFieldKeyListener());
textField.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
Object src = e.getSource();
if (src == null)
return;
if (src == textField) {
String fieldValue = textField.getText();
int currentValue = Integer.parseInt(fieldValue);
int maxValue = controller.getDocument().getNumberOfPages();
if (currentValue > maxValue)
textField.setText(String.valueOf(maxValue));
}
}
});
// start off with page 1.
textField.setText("1");
return textField;
}
代码示例来源:origin: org.icepdf.os/icepdf-viewer
/**
* Utility for building input field that handles page number limits for the
* current document.
*
* @return pageNumber text field with listeners for validation.
*/
private JTextField buildFloatTextField() {
final JTextField textField = new JTextField();
textField.setInputVerifier(new FloatTextFieldInputVerifier());
textField.addKeyListener(new FloatTextFieldKeyListener());
textField.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
Object src = e.getSource();
if (src == null)
return;
if (src == textField) {
String fieldValue = textField.getText();
// empty string, no problem we can allow that.
if ("".equals(fieldValue)) {
return;
}
float currentValue = Float.parseFloat(fieldValue);
textField.setText(String.valueOf(currentValue));
}
}
});
return textField;
}
代码示例来源:origin: huazhouwang/WIFIADB
private void initTexts(){
final InputVerifier verifier = new CustomInputVerifier(0,255);
for (JTextField item : mIPTextFields){
final NumberDocumentFilter documentFilter = new NumberDocumentFilter(3);
documentFilter.bind(item);
item.setInputVerifier(verifier);
}
final InputVerifier verifier2 = new CustomInputVerifier(1024,65535,Integer.valueOf(Config.DEFAULT_PORT));
final NumberDocumentFilter documentFilter = new NumberDocumentFilter(5);
documentFilter.bind(mPort);
mPort.setInputVerifier(verifier2);
mPort.setText(Config.DEFAULT_PORT);
listenOthers();
}
代码示例来源:origin: stackoverflow.com
tf1.setInputVerifier(new RangeVerifier());
代码示例来源:origin: jawi/ols
this.channelCount.setInputVerifier( JComponentInputVerifier.create( Integer.TYPE, "Invalid channel count!" ) );
this.channelCount.setToolTipText( "The number of channels contained in the raw data." );
this.sampleDepth.setInputVerifier( JComponentInputVerifier.create( Integer.TYPE, "Invalid sample depth!" ) );
this.sampleDepth.setToolTipText( "The number of samples to read from the input source." );
this.sampleRate.setInputVerifier( JComponentInputVerifier.create( Integer.TYPE, "Invalid sample rate!" ) );
this.sampleRate.setToolTipText( "The sample rate of the raw data, in Hertz." );
this.sampleWidth.setInputVerifier( JComponentInputVerifier.create( Integer.TYPE, "Invalid sample width!" ) );
this.sampleWidth.setToolTipText( "The number of bytes to read for each sample." );
代码示例来源:origin: undera/jmeter-plugins
skipLines = new JTextField(20);
Color lightRed = new Color(255, 202, 197);
skipLines.setInputVerifier(new IntegerInputVerifier(0, Integer.MAX_VALUE, skipLines.getBackground(), lightRed));
skipLines.setToolTipText("Number of initial lines of input to skip. Must be an integer >= 0.");
addToPanel(mainPanel, editConstraints, 1, 3, skipLines);
代码示例来源:origin: senbox-org/snap-desktop
customMenuLocation.setInputVerifier(new RequiredFieldValidator(Bundle.MSG_Empty_MenuLocation_Text()));
customMenuLocation.setEnabled(false);
代码示例来源:origin: kg.apc/jmeter-plugins-extras
skipLines = new JTextField(20);
Color lightRed = new Color(255, 202, 197);
skipLines.setInputVerifier(new IntegerInputVerifier(0, Integer.MAX_VALUE, skipLines.getBackground(), lightRed));
skipLines.setToolTipText("Number of initial lines of input to skip. Must be an integer >= 0.");
addToPanel(mainPanel, editConstraints, 1, 3, skipLines);
代码示例来源:origin: jawi/ols
this.heightEditor.setInputVerifier( JComponentInputVerifier.create( Integer.class,
"Invalid height! Must be a postive whole number." ) );
this.signalHeightEditor.setInputVerifier( JComponentInputVerifier.create( Integer.class,
"Invalid height! Must be a postive whole number." ) );
代码示例来源:origin: org.orbisgis/mapeditor
scaleField = new JTextField();
scaleField.addActionListener(scaleInputActionListener);
scaleField.setInputVerifier(new FormattedTextFieldVerifier());
内容来源于网络,如有侵权,请联系作者删除!