java - combine JSpinner with JFormattedTextField -


i want make customized jspinner editing day hours. want format 1hh:mm:ss a1, part.

i want add in functionalities of jformattedtextfield:

  1. setplaceholdercharacter('_')

    example time 09:23:45, when user delete 09,

    __:23:45 shows on screen.

  2. input restriction

    example time 09:23:45, when user delete 09,

    , try enter anything, can enter numbers, no letter allowed.

any appreciated!

there may better solution jformattedtextfield, here 1 built-in java classes. doesn't fit requirement replacing deleted numbers '_'. can select seconds , spinn seconds instead of hours. there input restriction. may write letters, no changeevent fired. additional bonus: don't have think when change next hour after 60 minutes or , works, of course, date can have (so spinning months or years possible, too)

public class hourspinner implements changelistener {  public static void main(string[] args) {     swingutilities.invokelater(new runnable() {         @override         public void run() {             new hourspinner();         }     }); }  public hourspinner() {      jframe frame = new jframe();     frame.setdefaultcloseoperation(jframe.exit_on_close);     frame.setsize(100, 70);     frame.setlocationrelativeto(null);      container contentpane = frame.getcontentpane();      jspinner datespinner = new jspinner(new spinnerdatemodel(new date(), null, null, calendar.hour_of_day));     dateeditor editor = new jspinner.dateeditor(datespinner, "hh:mm:ss");     datespinner.seteditor(editor);     datespinner.addchangelistener(this);      contentpane.add(datespinner);      frame.setvisible(true);  }  @override public void statechanged(changeevent e) {     jspinner source = (jspinner) e.getsource();     system.out.println(source.getvalue()); }  } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -