我正在使用swt jface与rcp一起研究eclipse java。 如何限制文本框中的字符。就像我的文本框中只需要4个字符一样,那我该怎么办?如果我想要字母数字组合怎么办?再次在一定限度内?
答案 0 :(得分:0)
请查看此功能示例以限制字符
function check_length_year(my_form) {
maxLen = 4; // max number of characters allowed
if (my_form.retire_year.value.length > maxLen) {
// Alert message if maximum limit is reached.
// If required Alert can be removed.
// var msg = "You have reached your maximum limit of characters allowed";
// alert(msg);
// Reached the Maximum length so trim the textarea
my_form.retire_year.value = my_form.retire_year.value.substring(0, maxLen);
return false;
} else { // Maximum length not reached so update the value of my_text counter
my_form.year_num.value = maxLen - my_form.retire_year.value.length;}
}
答案 1 :(得分:0)
这对你有用吗?
SWT / LimitthenumberofcharactersthattheStyledTextaccepts.htm“> HTTP://www.java2s.com/Tutorial/Java/0280_SWT/LimitthenumberofcharactersthattheStyledTextaccepts.htm
答案 2 :(得分:0)
答案的一半:
text.setTextLimit(4);