-1

I am starting to learn Java, could you please advise if adding an underline in input (System.in) is possible?

enter image description here

sampleDesign

package sampleDesign; 
import java.util.Scanner; 
class sampleDesign {

    public static void main(String[] args) {
        
        Scanner scan = new Scanner(System.in);
        
        System.out.println("-----------Label 1--------------");
        System.out.print("Design Input: " );
        String input1 = scan.nextLine();
    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Sasuke Scend
  • 111
  • 1
  • 2
  • 11
  • 1
    If you know what control characters you can use to move the cursor in the terminal program used for input you could do this. There isn't any standard way. – tgdavies Feb 09 '22 at 05:54
  • 2
    It sounds like you're trying to use the console as a GUI. That's not really what the console is for. I think you'll need to be patient, and wait till you've learnt how to actually write GUI code, before you try to do something like this. – Dawood ibn Kareem Feb 09 '22 at 06:05

1 Answers1

0

Can you? Yes. Should you, probably not.

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        System.out.print("Name: __________");
        System.out.print("\b");
        System.out.print("\b");
        System.out.print("\b");
        System.out.print("\b");
        System.out.print("\b");
        System.out.print("\b");
        System.out.print("\b");
        System.out.print("\b");
        System.out.print("\b");
        System.out.print("\b");
        Scanner scanner = new Scanner(System.in);
        scanner.nextLine();
    }
}

So, immediate problems, it's a pain to type and it won't restrict the user from input more characters.

Java's "terminal" support is pretty rudimentary. If you want any kind of "fancy" looking "terminal" inputs, you'd probably need to find a decent "curses" implementation/binding

as a few ... and no, I've not used any of them

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366