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 6992381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:37:38+00:00 2026-05-27T19:37:38+00:00

while editing cell value in JTable it’s value suddenly appears in exponential form(i.e. 1.7E10)

  • 0

while editing cell value in JTable it’s value suddenly appears in exponential form(i.e. 1.7E10) instead of being displayed in normal user friendly form.

How can I change the number formatting while editing cell value?

…

The Solution Was really simple, had to create my own TableCellEditor like that:

 public static class Double2DecimalEditor extends AbstractCellEditor implements TableCellEditor{

    private static final long serialVersionUID = 1L;
    private JComponent component = new JTextField();
    private NumberFormat nf;

    @Override
    public Object getCellEditorValue() {
        System.out.println("getCellEditorValue");
        NumberFormat nf = new DecimalFormat("#,###.###");
        String text = ((JTextField)component).getText();
        System.out.println("TEXT = " + ((JTextField)component).getText());
        return nf.format(Double.parseDouble(text));
    }

    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        System.out.println("getCellEditorComponent");
        Double data = Double.valueOf(value.toString().replace(",", ""));
        NumberFormat nf = new DecimalFormat("#.###");
        ((JTextField)component).setText(nf.format(data));
        ((JTextField)component).setHorizontalAlignment(SwingConstants.RIGHT);
        return component;
    }
}

THANKS to everybody for advices!

  • 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-05-27T19:37:38+00:00Added an answer on May 27, 2026 at 7:37 pm

    As far as i see its this line that breaks your code

    textField.setText((value != null) ? value.toString() : "");
    

    this happens in the javax.swing.DefaultCellEditor#DefaultCellEditor that is used by the JTable.

    You will have to add your own editor that applies formatting .

    should be similar too

    table.setDefaultEditor(Double.class, new DefaultCellEditor(new JTextField())
        {
          public Component getTableCellEditorComponent( JTable table, Object value,
                                                        boolean isSelected,
                                                        int row, int column )
          {
            String formattedvalue = formatyourvalue(value);
            delegate.setValue(formattedvalue);
            return editorComponent;
          }
        });
    

    applied to the example you change the makeTable with

      private static JTable makeSampleTable()
      {
        String[] columnNames = {"String", "Integer", "Boolean", "Double"};
        Object[][] data = {{"AAA", 12, true, 111111111111.15},
                           {"BBB", 1, false, 11199999111.15}, {"CCC", 2, true, 1155555511111.15},};
        DefaultTableModel m = new DefaultTableModel(data, columnNames)
        {
    
          private static final long serialVersionUID = 1L;
    
          @Override
          public Class<?> getColumnClass( int column )
          {
            return getValueAt(0, column).getClass();
          }
        };
        JTable table = new JTable(m);
        TableColumnModel tm = table.getColumnModel();
        tm.getColumn(3).setCellRenderer(new Double2DecimalRenderer());
        table.setDefaultEditor(Double.class, new DefaultCellEditor(new JTextField())
        {
          public Component getTableCellEditorComponent( JTable table, Object value,
                                                        boolean isSelected,
                                                        int row, int column )
          {
            NumberFormat nf;
            nf = NumberFormat.getNumberInstance();
            nf.setMinimumFractionDigits(2);
            nf.setMaximumFractionDigits(2);
            if ( ( value != null ) && ( value instanceof Number ) )
              {
              Number numberValue = (Number) value;
              delegate.setValue(nf.format(numberValue.doubleValue()));
              }
            else
              {
              delegate.setValue(value);
              }
            return editorComponent;
          }
        });
        return table;
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how can i indent my CUSTOM CELL while editing, resizing or moving labels and
While editing an aspx file I found both these opening tags used for seemingly
While editing .scm files it would be great if Vim would automatically put the
Often while editing config files, I'll open one with vi and then when I
I use Visual Studio's Code Snippet feature pretty heavily while editing c# code. I
I've created new db via phpMyAdmin and while editing db privilages clicked delete localhost
While editing HTML/ASPX/ASCX etc in visual studio 2005; whenever I select an html tag,
Is it possible to make the website unavailable while editing it, while online? If
In Visual Studio 2008, while editing the web page, it is displaying some error
Ask a question, and while editing the body of your question, click on some

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.