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

  • SEARCH
  • Home
  • 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 8901711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:25:41+00:00 2026-06-15T01:25:41+00:00

I import a CSV file into a DefaultTableModel , one column is formatted as

  • 0

I import a CSV file into a DefaultTableModel, one column is formatted as double, so far so good. But if I edit a cell from this column (double) in the JTable, after that this cell is no longer a double. Now it is a string.
How can I change the type of the edited cell in the TableModel?
I know that I can parse a string to double with double value = Double.parseDouble(str);, but how can I ensure that this happens after editing a cell?

Do I need a new TableModel-class like:

class myTableModel extends DefaultTableModel { }

Thanks for your help.

  • 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-15T01:25:42+00:00Added an answer on June 15, 2026 at 1:25 am
    • have to override getColumnClass for required column(s)

    for example

        @Override
        public Class<?> getColumnClass(int c) {
            if (c == 1) {
                return Short.class;
            } else {
                return Integer.class;
            }
        }
    

    or

    import javax.swing.*;
    import javax.swing.table.*;
    
    public class RemoveAddRows extends JFrame {
    
        private static final long serialVersionUID = 1L;
        private Object[] columnNames = {"Type", "Company", "Shares", "Price"};
        private Object[][] data = {
            {"Buy", "IBM", new Integer(1000), new Double(80.50)},
            {"Sell", "MicroSoft", new Integer(2000), new Double(6.25)},
            {"Sell", "Apple", new Integer(3000), new Double(7.35)},
            {"Buy", "Nortel", new Integer(4000), new Double(20.00)}
        };
        private JTable table;
        private DefaultTableModel model;
        private javax.swing.Timer timer = null;
    
        public RemoveAddRows() {
            model = new DefaultTableModel(data, columnNames) {
    
                private static final long serialVersionUID = 1L;
    
                @Override
                public Class getColumnClass(int column) {
                    return getValueAt(0, column).getClass();
                }
            };
            table = new JTable(model);        
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            JScrollPane scrollPane = new JScrollPane(table);
            add(scrollPane);        
        }
    
    
    
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    RemoveAddRows frame = new RemoveAddRows();
                    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to import about 10000 rows (from a CSV file) into an
When importing a CSV file into Excel, it only strips the double-quotes from the
I am trying to import a txt/csv file into my postgres database from php
I am using openrowset to import a csv file into SQL Server. One of
How to write multiple numpy arrays into one csv file in multiple columns? import
How can I import a CSV file into a MySQL table? I would like
I want to import the contents of a csv file into R, the csv
I am trying to import a csv file to insert data into an existing
i want to import csv file to mysql database. the upload was success. but
I'm working on an import from a CSV file to my ASP.NET MVC3/C#/Entity Framework

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.