JTable Synchronization with Back-End Data-Structure
In the provided data-structure, the ranges are represented as NavigableMaps, and each range contains a NavigableMap of values and their corresponding Boolean values. The question arises whether to maintain synchronization between the data-structure and the JTable during user editing.
Synchronization Approach
It is recommended to recreate the data-structure once the user completes editing the JTable. This approach ensures that the data-structure is updated only after all changes have been made and validated.
Custom Editor for Data Validation
To handle data validation, consider creating a custom editor that displays a popup dialog with two separate text fields for each value in the range. This allows users to edit each value as a double within the specified range. Before saving the edited value to the model, it is formatted as a string using a custom function that ensures compliance with the range.
Example of Custom Editor
Below is an example of a custom editor using a popup dialog:
public class TablePopupEditor extends DefaultCellEditor { private PopupDialog popup; private String currentText = ""; private JButton editorComponent; // ... (continued from above) public static void main(String[] args) { // ... (creating table and popup editor) JFrame frame = new JFrame("Popup Editor Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(scrollPane); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } } class PopupDialog extends JDialog implements ActionListener { // ... (continued from above) }
The above is the detailed content of How to Synchronize a JTable with a Back-End NavigableMap Data Structure During User Editing?. For more information, please follow other related articles on the PHP Chinese website!