2 Replies Latest reply on Jul 7, 2014 12:20 PM by TPD-Opitz

    JPanel as TableCellEditor in JTable


      In my Java panel I have a JTable in which two of the columns use the JDateChooser object, from the package com.toedter.calendar, via a custom cell editor.  For those who don't know, the JDateChooser object is a JPanel containing a JFormattedTextField and a JButton.  Unlike cells that use text boxes or other simple components, which you can type into without having to click the cell beforehand, this functionality is not present on date-chooser cells. As far as my current understanding goes, this is because my custom editor's returns the JDateChooser object as the component (via the getTableCellEditorComponent method). Since JDateChooser's parent class is JPanel (according to the API), that's what it's trying to edit, and of course, you can't type text into a JPanel.


      At first, I managed to get the editor to set the focus in the text field when I key into one of those cells.  However, the first digit would not be added to the text field, for example, "05012014" becomes "50/12/014_".  In order to get around this, I tried making a custom version of the JDateChooser class, overwriting the method processKeyBinding.  The idea is to get the field's text, replace the next space character with the new digit, and re-set the text.  However, for some reason the setText() method I used didn't work.


      Is my approach wrong?  Is there some way to do this correctly, using the processKeyBinding method or otherwise?