Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7828133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:13:06+00:00 2026-06-02T10:13:06+00:00

I have set a cell editor for one of the columns to be a

  • 0

I have set a cell editor for one of the columns to be a JSpinner and it works, but when the data in the data model changes the editor i enabled before is still enabled nad it shows the value form the old row (it does not exist or it is in a different place in the changed data).

How can i make the editor for the selected cell disappear saving the entered value when the data changes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:13:09+00:00Added an answer on June 2, 2026 at 10:13 am

    this one could be good code for your SSCCE

    enter image description here

    import java.awt.*;
    import java.util.EventObject;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    
    public class SpinnerColumn extends AbstractCellEditor implements TableCellEditor, TableCellRenderer {
    
        private static final long serialVersionUID = 1L;
        private JSpinner editSpinner, renderSpinner;
        private JTable table;
        private String[] list;
        private Border originalBorder;
    
        public SpinnerColumn(JTable table, int column) {
            editSpinner = new JSpinner();
            renderSpinner = new JSpinner();
            originalBorder = editSpinner.getBorder();
            editSpinner.setBorder(new LineBorder(Color.BLUE));
            this.table = table;
            table.getColumnModel().getColumn(column).setCellEditor(this);
        }
    
        public SpinnerColumn(String[] list, JTable table, int column) {
            editSpinner = new JSpinner();
            editSpinner.setModel(new SpinnerListModel(list));
            renderSpinner = new JSpinner();
            originalBorder = editSpinner.getBorder();
            editSpinner.setBorder(new LineBorder(Color.BLUE));
            this.list = list;
            this.table = table;
            table.getColumnModel().getColumn(column).setCellEditor(this);
        }
    
        @Override
        public Object getCellEditorValue() {
            return editSpinner.getValue();
        }
    
        @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
                int row, int column) {
            if (list != null) {
                editSpinner.setValue(list[0]);
            } else {
                editSpinner.setValue(0);
            }
            if (value != null) {
                editSpinner.setValue(value);
            }
            return editSpinner;
        }
    
        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            if (hasFocus) {
                renderSpinner.setBorder(new LineBorder(Color.BLUE));
            } else {
                renderSpinner.setBorder(originalBorder);
            }// *** here's where we set the spinner's value
            if (value == null) {
                renderSpinner.setValue(0);
            } else {
                int intValue = ((Integer) value).intValue();
                renderSpinner.setValue(intValue);
            }
            return renderSpinner;
        }
    
        @Override
        public boolean isCellEditable(EventObject evt) {
            return true;
        }
    
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    JFrame frame = new JFrame("SpinnerColumn");
                    JPanel panel = new JPanel(new GridLayout(1, 1));
                    JTable table = new JTable(5, 1);
                    SpinnerColumn spinnerColumn = new SpinnerColumn(table, 0);
                    table.setDefaultRenderer(Object.class, spinnerColumn);
                    panel.add(table);
                    frame.setContentPane(panel);
                    frame.pack();
                    frame.setVisible(true);
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my JavaFX TableView I have one TableColumn on which I have set Cell
In my tableview i have set xml data to display but until scroll it
I am working with some spreadsheet data and I have a set of cell
I have a custom UITableViewCell subclass. I have set the contentView of my cell
I have a <Grid> set up just the way I want with each cell
I have set a background on the data-role=page element like so <div data-role=page style=background:
I'm trying to create a datatable with the in cell editor. I have a
I have a DataGrid with a NumericStepper as the item editor for one of
I have set a CSS property table-cell for a div. I have also specified
In my grid view i have set bottom border for all cell because of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.