java - Fetch double value from customized JSlider -
i have created jslider 0 1 increment of 0.1. wrote following code implement not sure how fetch values slider since function getvalue() fetches integer values. in case fetches 10 no matter move slider. please can tell me how can fetch double values slider.
slider=new jslider(); slider.setmajortickspacing(1); slider.setmaximum(10); slider.setpaintlabels(true); slider.setpaintticks(true); slider.setpreferredsize(new java.awt.dimension(230, 46)); format f = new decimalformat("0.0"); hashtable<integer, jcomponent> labels = new hashtable<integer, jcomponent>(); for(int i=0;i<=10;i++){ jlabel label = new jlabel(f.format(i*0.1)); label.setfont(label.getfont().derivefont(font.plain)); labels.put(i,label); } slider.setlabeltable(labels);
following code listener
slider.addchangelistener(new changelistener() { public void statechanged(changeevent event) { if(!slider.getvalueisadjusting()) { double value = slider.getvalue(); system.out.println("value"+value); } } });
thanks in advance.
regards, colin
your code works is. change did divide 10.0 double:
slider.addchangelistener(new changelistener() { public void statechanged(changeevent event) { if (!slider.getvalueisadjusting()) { double v = slider.getvalue() / 10.0; system.out.println("value: "+v); } } });
Comments
Post a Comment