java - How can I implement FocusListener of JDatePicker? -
i want perform function in focusevent
of jdatepicker
. using below code implementing focuslistener
.
properties p = new properties(); p.put("text.today", "today"); p.put("text.month", "month"); p.put("text.year", "year"); utildatemodel model = new utildatemodel(); calendar today=calendar.getinstance(); date todaydate=new date(); today.settime(todaydate); model.setdate(today.get(calendar.year), today.get(calendar.month), today.get(calendar.date)); model.setselected(true); jdatepanelimpl datepanel =new jdatepanelimpl(model, p); jdatepickerimpl datepicker = new jdatepickerimpl(datepanel,new datelabelformatter()); datepicker.addfocuslistener(new focuslistener() { @override public void focuslost(focusevent e) { // todo auto-generated method stub system.out.println("fcus lost"); } @override public void focusgained(focusevent e) { // todo auto-generated method stub system.out.println("focus gained"); swingutilities.invokelater(new runnable() { @override public void run() { // todo auto-generated method stub //repaint(); displayimage(categoryattributeobj,imgroupobj); } }); } });
this code not working. error in code?
i'm not particular fan of jdatepicker
, number of personal reasons.
you implement own version provided functionality after or try swinglabs, swingx jxdatepicker
instead, example
import java.awt.dimension; import java.awt.eventqueue; import java.awt.graphics; import java.awt.graphics2d; import java.awt.event.focusadapter; import java.awt.event.focusevent; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.uimanager; import javax.swing.unsupportedlookandfeelexception; import org.jdesktop.swingx.jxdatepicker; public class main { public static void main(string[] args) { new main(); } public main() { eventqueue.invokelater(new runnable() { @override public void run() { try { uimanager.setlookandfeel(uimanager.getsystemlookandfeelclassname()); } catch (classnotfoundexception | instantiationexception | illegalaccessexception | unsupportedlookandfeelexception ex) { ex.printstacktrace(); } jframe frame = new jframe("testing"); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.add(new testpane()); frame.pack(); frame.setlocationrelativeto(null); frame.setvisible(true); } }); } public class testpane extends jpanel { public testpane() { add(new jbutton("before")); jxdatepicker picker = new jxdatepicker(); picker.geteditor().addfocuslistener(new focusadapter() { @override public void focusgained(focusevent e) { system.out.println("you have foucs"); } }); add(picker); add(new jbutton("after")); } } }
Comments
Post a Comment