- Forward


Cell Editors
in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Review
Back SMYC Forward
  • Collection-Backed GUI Components:
    • Can contain objects of any class but, by default, render the String representation
  • Custom Cell Renderers:
    • Are "stamps" that the Component can use to render individual elements
Motivation
Back SMYC Forward
  • Editable Collection-Backed GUI Components:
    • JComboBox and JTable have cells that are, in principal, editable
  • The Need:
    • A Component that can, temporarily, be displayed at the location of the cell and used to edit the contents of that cell
Existing Hooks
Back SMYC Forward
  • JComboBox:
    • Has a setEditor() method that is passed an object that implements the ComboBoxEditor interface
  • JTable:
    • JTable has a setDefaultEditor() method that is passed an object that implements the TableCellEditor
    • TableColumn has a setCellEditor() method that is passed an object that implements the TableCellEditor
An Example
Back SMYC Forward

A Supporting Class

javaexamples/celleditor/Course.java
 
An Example (cont.)
Back SMYC Forward

The Component

javaexamples/celleditor/CourseField.java
 
An Example (cont.)
Back SMYC Forward

The Editor

javaexamples/celleditor/CourseCellEditor.java
 
An Example (cont.)
Back SMYC Forward

A Model for the JTable

javaexamples/celleditor/GenericTableModel.java
 
An Example (cont.)
Back SMYC Forward

The Application

javaexamples/celleditor/CourseCellEditorDemo.java
 
An Additional Requirement of ComboBoxEditor
Back SMYC Forward
  • The Issue:
    • A JComboBox has ActionListener objects that are notified when the editing is complete (e.g., when the user presses Enter in a text-based instance) so custom editors must provide this capability
  • Adding ActionListener Support:
    • This functionality can be provided using an event multicaster
There's Always More to Learn
Back -