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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:36:17+00:00 2026-05-23T12:36:17+00:00

I have a JTable where i enter some values. This is the listener function

  • 0

I have a JTable where i enter some values. This is the listener function to know if it has been made any change at the values, so i can update them. Values must have the format indicated (#.###), so I’m doing this fix to round the float to 3 decimal places if the client enter more than 3.

    private class CambioTablaPretratamientoListener implements TableModelListener{
    public void tableChanged(TableModelEvent e){
        try{
            if(enviarDatosADispositivo){
                TableModel model = (TableModel)e.getSource();
                float value = Float.parseFloat((String)model.getValueAt(e.getLastRow(), 1));
                DecimalFormat dec = new DecimalFormat("#.###");
                String aux = dec.format(value);
                if(model.getValueAt(e.getLastRow(), 1).equals(aux))
                    return;
                else
                    model.setValueAt(aux, e.getLastRow(), 1);
                value = Float.parseFloat(aux);

                String nombreAtributo = (String)model.getValueAt(e.getLastRow(), 0);

                nodoAModificar.setPretratamientUserParameter(nombreAtributo, value);     
            }
        }catch(BusinessException ex){
            ex.printStackTrace();
        }
    }
}

Code seems to work at first, because it rounds and the number appears in the table, but the value is not getting updated. I guess I’m doing something wrong with the DecimalFormat, because if I leave the function like this one, it works:

    private class CambioTablaPretratamientoListener implements TableModelListener{
    public void tableChanged(TableModelEvent e){
        try{
            if(enviarDatosADispositivo){
                TableModel model = (TableModel)e.getSource();
                float value = Float.parseFloat((String)model.getValueAt(e.getLastRow(), 1));
                String nombreAtributo = (String)model.getValueAt(e.getLastRow(), 0);

                nodoAModificar.setPretratamientUserParameter(nombreAtributo, value);     
            }
        }catch(BusinessException ex){
            ex.printStackTrace();
        }
    }
}

And finall

  • 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-23T12:36:18+00:00Added an answer on May 23, 2026 at 12:36 pm

    If you use BigDecimal, you could actually truncate the numbers, instead of trying to use Float’s (lack of) precision.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JTable and need to change some of it's properties, such as
I have set some parameters for my JTable, but it seems they are in
I have an application where I have a JTable with line breaks(pressing Enter key
I have a JTable instance, containing a number of rows. The columns in this
I followed some tips in this guide: JTable with horizontal scrollbar but still having
I would like to have some exemple of implementation of jXSearchPanel with jTable. I
I have a JTable which has certain cells editable. If the user enters in
I have a JTable where I want to highlight some rows using a custom
I have a JTable . I want to know which row and column are
I have a very simple Java JTable question. I am creating this class to

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.