1

can you help me with input mask?

String format = "X-XX-XXX"

X is the user input from console / keyboard.

I keep wanting to show the dash (-) while the user input to the string format.

Can you help me to solve my problem?

ivan angelo
  • 157
  • 1
  • 8

2 Answers2

2

It's impossible to show the entire mask while typing, but what you can do is read individual chars in at a time and when you get to the relevant places, output a dash.

Edit: It may be possible to move the cursor in the console, that way you can output the mask and then manoeuvre the cursor accordingly (depending on how many keys have been pressed).

I just found this here:

char escCode = 0x1B;
int row = 10; int column = 10;
System.out.print(String.format("%c[%d;%df",escCode,row,column));

Which should move the cursor to position 10,10 on the console.

Community
  • 1
  • 1
Liam George Betsworth
  • 18,373
  • 5
  • 39
  • 42
0

Unfortunately, there is no unbuffered console I/O for java. You have to bind curses via JNI probably:

http://plindenbaum.blogspot.com/2008/01/java-native-interface-jni-notebook.html

execc
  • 1,083
  • 12
  • 25
  • So , Im going to use console.nextLine(). But when the dashes are already there. After I inserting the first character, it will jump to the third character (beside the dash (-)) and so on. – ivan angelo May 14 '12 at 16:35