how to lose the focus of JtextFeild onClick
how to lose focus of JFormatedTextfeild when click on Calender Window
private void dateTxtFocusGained(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
PickDate ex=new PickDate();
// dateTxt.setText(Helper.pickDate.toString());
}
...
private class MyDateListener implements DateListener
{
public void dateChanged(DateEvent e)
{
Calendar c = e.getSelectedDate();
开发者_运维知识库if (c != null) {
formatTxt.setText(c.getTime());
PickDate.this.dispose(); // pickdate is nothing but JFrame in which calender shows
}
else {
System.out.println("No time selected.");
}
}
}
One hack I have used in the past is to toggle the focusability of the component. In your onClick event:
//we just want to lose current caret focus
//but still have textfield be focusable
dateTxt.setFocusable(false);
dateTxt.setFocusable(true);
精彩评论