添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I creates a dataTable and cellEditor form one column. This column is simple jSpinner. I have the following problem. When I enter some value in the spinner and select the another row, the value in the previous row won't be changed. If I press , it'll done. If I select or button, it will done too. But if I enter value and change selection, it won't be done. Help, please. Here is the CellEditor code.

public class DurationTableCellEditor extends AbstractCellEditor implements TableCellEditor{
final JSpinner spinner = new JSpinner();
// Initializes the spinner.
public DurationTableCellEditor() {
    spinner.setModel(new SpinnerNumberModel(1,1,50000,1));        
// Prepares the spinner component and returns it.
public Component getTableCellEditorComponent(JTable table, Object value,
        boolean isSelected, int row, int column) {
    spinner.setValue(new Integer(value.toString()).intValue());
    spinner.setCursor(null);
    return spinner;
// Enables the editor only for double-clicks.
@Override
public boolean isCellEditable(EventObject evt) {
    if (evt instanceof MouseEvent) {
        return ((MouseEvent)evt).getClickCount() >= 1;
    return true;
// Returns the spinners current value.
public Object getCellEditorValue() {
    return spinner.getValue();

It's not clear how you're updating your data model, but one approach would be to implement ChangeListener in your CellEditor, much as this example implements ItemListener. For reference, see How to Use Tables: Using Other Editors. In particular, look at fireEditingStopped(). Finally, you'll need a corresponding TableCellRenderer.

// Returns the spinners current value.
public Object getCellEditorValue() {
    spinner.commitEdit();
    return spinner.getValue();
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.