Class DateTimeTableEditor

  • All Implemented Interfaces:
    java.io.Serializable, javax.swing.CellEditor, javax.swing.table.TableCellEditor, javax.swing.table.TableCellRenderer

    public class DateTimeTableEditor
    extends javax.swing.AbstractCellEditor
    implements javax.swing.table.TableCellEditor, javax.swing.table.TableCellRenderer
    DateTimeTableEditor, This class is used to add a DateTimePicker to cells (or entire columns) of a Swing JTable or a SwingX JXTable component. This class can be used as a table cell "Editor", or as a "Renderer", or as both editor and renderer. Separate class instances should be used for the editor and the renderer. // Usage example: // Create a table. JTable table = new JTable(); //Set up a renderer and editor for the LocalDateTime type. table.setDefaultRenderer(LocalDateTime.class, new DateTimeTableEditor()); table.setDefaultEditor(LocalDateTime.class, new DateTimeTableEditor()); The DateTimePicker and Settings: The DateTimePicker and picker settings can be accessed with the supplied getter functions. Note that most of the settings for the DateTimePicker are left at their default values, but a few (mostly cosmetic) settings are changed in the DateTimeTableEditor constructor. See the DateTimeTableEditor constructor implementation to learn which default settings were changed. Auto adjust row height: By default, this class will automatically adjust the minimum height of all table rows. This occurs during the first time that any cell with an editor or render is displayed. The row height is only adjusted if the current table row height value is below the minimum value that is needed to display the DateTimePicker component. This auto adjust behavior can be turned off from the constructor.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int clickCountToEdit
      clickCountToEdit, An integer specifying the number of clicks needed to start editing.
      • Fields inherited from class javax.swing.AbstractCellEditor

        changeEvent, listenerList
    • Constructor Summary

      Constructors 
      Constructor Description
      DateTimeTableEditor()
      Constructor, default.
      DateTimeTableEditor​(boolean autoAdjustMinimumTableRowHeight, boolean matchTableBackgroundColor, boolean matchTableSelectionBackgroundColor)
      Constructor, with options.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object getCellEditorValue()
      getCellEditorValue, This returns the value contained in the editor.
      DatePickerSettings getDatePickerSettings()
      getDatePickerSettings, Returns the DatePicker settings for the DateTimePicker used by this class.
      DateTimePicker getDateTimePicker()
      getDateTimePicker, Returns the DateTimePicker which is used by this class.
      java.awt.Component getTableCellEditorComponent​(javax.swing.JTable table, java.lang.Object value, boolean isSelected, int row, int column)
      getTableCellEditorComponent, this returns the editor that is used for editing the cell.
      java.awt.Component getTableCellRendererComponent​(javax.swing.JTable table, java.lang.Object value, boolean isSelected, boolean hasFocus, int row, int column)
      getTableCellRendererComponent, Returns the renderer that is used for drawing the cell.
      TimePickerSettings getTimePickerSettings()
      getTimePickerSettings, Returns the TimePicker settings for the DateTimePicker used by this class.
      boolean isCellEditable​(java.util.EventObject anEvent)
      isCellEditable, Returns true if anEvent is not a MouseEvent.
      void setCellEditorValue​(java.lang.Object value)
      setCellEditorValue, This sets the picker to an appropriate value for the supplied object.
      • Methods inherited from class javax.swing.AbstractCellEditor

        addCellEditorListener, cancelCellEditing, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, removeCellEditorListener, shouldSelectCell, stopCellEditing
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface javax.swing.CellEditor

        addCellEditorListener, cancelCellEditing, removeCellEditorListener, shouldSelectCell, stopCellEditing
    • Field Detail

      • clickCountToEdit

        public int clickCountToEdit
        clickCountToEdit, An integer specifying the number of clicks needed to start editing. Even if clickCountToEdit is defined as zero, it will not initiate until a click occurs.
    • Constructor Detail

      • DateTimeTableEditor

        public DateTimeTableEditor()
        Constructor, default.
      • DateTimeTableEditor

        public DateTimeTableEditor​(boolean autoAdjustMinimumTableRowHeight,
                                   boolean matchTableBackgroundColor,
                                   boolean matchTableSelectionBackgroundColor)
        Constructor, with options.
        Parameters:
        autoAdjustMinimumTableRowHeight - Set this to true to have this class automatically adjust the the minimum row height of all rows in the table, the first time that a DateTimeTableEditor is displayed. Set this to false to turn off any row height adjustments. The default value is true.
    • Method Detail

      • getCellEditorValue

        public java.lang.Object getCellEditorValue()
        getCellEditorValue, This returns the value contained in the editor. This is required by the CellEditor interface.
        Specified by:
        getCellEditorValue in interface javax.swing.CellEditor
      • getDateTimePicker

        public DateTimePicker getDateTimePicker()
        getDateTimePicker, Returns the DateTimePicker which is used by this class.
      • getDatePickerSettings

        public DatePickerSettings getDatePickerSettings()
        getDatePickerSettings, Returns the DatePicker settings for the DateTimePicker used by this class. These settings can be adjusted as desired by the programmer.
      • getTimePickerSettings

        public TimePickerSettings getTimePickerSettings()
        getTimePickerSettings, Returns the TimePicker settings for the DateTimePicker used by this class. These settings can be adjusted as desired by the programmer.
      • getTableCellEditorComponent

        public java.awt.Component getTableCellEditorComponent​(javax.swing.JTable table,
                                                              java.lang.Object value,
                                                              boolean isSelected,
                                                              int row,
                                                              int column)
        getTableCellEditorComponent, this returns the editor that is used for editing the cell. This is required by the TableCellEditor interface. For additional details, see the Javadocs for the function: TableCellEditor.getTableCellEditorComponent().
        Specified by:
        getTableCellEditorComponent in interface javax.swing.table.TableCellEditor
      • getTableCellRendererComponent

        public java.awt.Component getTableCellRendererComponent​(javax.swing.JTable table,
                                                                java.lang.Object value,
                                                                boolean isSelected,
                                                                boolean hasFocus,
                                                                int row,
                                                                int column)
        getTableCellRendererComponent, Returns the renderer that is used for drawing the cell. This is required by the TableCellRenderer interface. For additional details, see the Javadocs for the function: TableCellRenderer.getTableCellRendererComponent().
        Specified by:
        getTableCellRendererComponent in interface javax.swing.table.TableCellRenderer
      • isCellEditable

        public boolean isCellEditable​(java.util.EventObject anEvent)
        isCellEditable, Returns true if anEvent is not a MouseEvent. Otherwise, it returns true if the necessary number of clicks have occurred, and returns false otherwise.
        Specified by:
        isCellEditable in interface javax.swing.CellEditor
        Overrides:
        isCellEditable in class javax.swing.AbstractCellEditor
      • setCellEditorValue

        public void setCellEditorValue​(java.lang.Object value)
        setCellEditorValue, This sets the picker to an appropriate value for the supplied object. If the value is null, then picker will be cleared. If the value is a LocalDateTime instance, then the picker will be set to that value. All other types (including strings) will be read or converted to a string with a maximum length of the first 100 characters. The date picker text will be set with the resulting string.