Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't disable keyboard editing inside Jtable #138

Open
panappl3 opened this issue Oct 26, 2021 · 1 comment
Open

Can't disable keyboard editing inside Jtable #138

panappl3 opened this issue Oct 26, 2021 · 1 comment

Comments

@panappl3
Copy link

I want to add a Datepicker inside my Jtable. Everything works fine except two things:

  1. Keyboard editing is still enabled although I explicitly disabled it.
  2. 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.

@panappl3 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
@panappl3 panappl3 reopened this Oct 26, 2021
@panappl3
Copy link
Author

panappl3 commented Oct 26, 2021

I fixed it myself:

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));

}

Any tips are still much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant