Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

TextFields for IP address input  RSS feed

 
Bruce Xu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,ranchers
In my current project I created 4 TextField inputs for IP address,such as:
TextField1-TextField2-TextField3-TextField4
and for each TextField,the requirements are:
1.only numbers allowered
2.only allows 3-digit number
3.numbers must be between 0~255
(for any violations to above requirements,users will get beeps)

my first solution is using JFormatterTextField:
......
editFormat = NumberFormat.getNumberInstance();
editFormat.setMinimumIntegerDigits(0);
editFormat.setMaximumIntegerDigits(3);
NumberFormatter EditFormatter = new NumberFormatter(editFormat);
EditFormatter.setMinimum(new Double(0));
EditFormatter.setMaximum(new Double(255));
EditFormatter.setAllowsInvalid(false);//don't comment out this line
TextField1 = new JFormattedTextField(new DefaultFormatterFactory(
editFormatter,editFormatter,editFormatter));
......
it works,but not perfect,because you cannot backspace the first digit.

In my second solution,I'm trying to use KeyAdapter to control KeyEvents on these TextFields,however still not perfect.

Is there any simple ways or utilities in Java to solve the similar problems?
Especially about IP address input format?

thanks in advance
 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you can get the component after you google it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!