You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to add a Datepicker inside my Jtable. Everything works fine except two things:
Keyboard editing is still enabled although I explicitly disabled it.
When selecting a date the default date format is displayed until the cell is not selected anymore. Then my custom date format is applied. I want to have my custom format to be applied all the time.
This is how I add the Datepicker inside my custom JTable class:
private void addDatePicker() {
DateTableEditor d = new DateTableEditor();
DatePickerSettings s = new DatePickerSettings();
s.setAllowKeyboardEditing(false);
s.setFormatForDatesCommonEra("EEEE, dd. LLL. yy");
d.getDatePicker().setSettings(s);
d.getDatePicker().setDateToToday();
this.setDefaultRenderer(LocalDate.class, d);
this.setDefaultEditor(LocalDate.class, new DateTableEditor());
TableColumn column = this.getColumnModel().getColumn(0);
column.setCellEditor(this.getDefaultEditor(LocalDate.class));
column.setCellRenderer(this.getDefaultRenderer(LocalDate.class));
}
Thank you in advance.
The text was updated successfully, but these errors were encountered:
panappl3
changed the title
Can't disable keyboard editing inside Jtable. Any help is much appreciated!!
Can't disable keyboard editing inside Jtable
Oct 26, 2021
For the tables Default Editor I gave a new DateTableEditor object as parameter without my settings.
But when I used my DateTableEditor object with my custom settings for the DefaultRenderer and the DefaultEditor it gave me some weird visual issues.
My solution is to declare two DateTableEditor objects, with the same settings (but different settings objects) for the DefaultEditor and the DefaultRenderer. This might be redundant and unnecessary but I can't seem to find a better solution. This is my new code:
private void addDatePicker() {
DateTableEditor dR = new DateTableEditor();
DateTableEditor dE = new DateTableEditor();
DatePickerSettings sR = new DatePickerSettings();
DatePickerSettings sE = new DatePickerSettings();
sR.setAllowKeyboardEditing(false);
sR.setFormatForDatesCommonEra("EEEE, dd. LLL. yy");
sE.setAllowKeyboardEditing(false);
sE.setFormatForDatesCommonEra("EEEE, dd. LLL. yy");
dR.getDatePicker().setSettings(sR);
dR.getDatePicker().setDateToToday();
dE.getDatePicker().setSettings(sE);
dE.getDatePicker().setDateToToday();
this.setDefaultRenderer(LocalDate.class, dR);
this.setDefaultEditor(LocalDate.class, dE);
TableColumn column = this.getColumnModel().getColumn(0);
column.setCellEditor(this.getDefaultEditor(LocalDate.class));
column.setCellRenderer(this.getDefaultRenderer(LocalDate.class));
I want to add a Datepicker inside my Jtable. Everything works fine except two things:
This is how I add the Datepicker inside my custom JTable class:
private void addDatePicker() {
DateTableEditor d = new DateTableEditor();
DatePickerSettings s = new DatePickerSettings();
s.setAllowKeyboardEditing(false);
s.setFormatForDatesCommonEra("EEEE, dd. LLL. yy");
d.getDatePicker().setSettings(s);
d.getDatePicker().setDateToToday();
this.setDefaultRenderer(LocalDate.class, d);
this.setDefaultEditor(LocalDate.class, new DateTableEditor());
TableColumn column = this.getColumnModel().getColumn(0);
column.setCellEditor(this.getDefaultEditor(LocalDate.class));
column.setCellRenderer(this.getDefaultRenderer(LocalDate.class));
}
Thank you in advance.
The text was updated successfully, but these errors were encountered: