问题
I have been trying to custom JFormattedTextField
to display a mask for entering an IP address.
I read javadoc, and I tried with ###.###.###.###
, but it's not valid in many cases.
I found some article for this, they use Regex to format value but they don't display a mask for entering an IP.
I want to display 3 dots in text field to display IP address. Like this:
. . .
I can input a IP Address in many cases. You can see in IPv4 configuration in Windows.
. . .
Can you help me? Thanks for reading
回答1:
You could try four JFormattedTextField
in a row, each separated by a JLabel(".")
. With the dot out of the way, that might make the number format easier to get right.
回答2:
I know this won't help you with your homework, but for other people looking for a solution: Jidesoft Grids (I am not affiliated) has a class for this: com.jidesoft.field.IPTextField.
Generally, I think it will be difficult to achieve a satisfactory solution with JFormattedTextField.
来源:https://stackoverflow.com/questions/12105639/how-to-custom-formatter-jformattedtextfield-to-display-an-ip-address