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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:55:42+00:00 2026-05-27T03:55:42+00:00

When i click the Button Sale, the Table must show in the first row,

  • 0

When i click the Button “Sale”, the Table must show in the first row, which item i sold, and how much was it. But when i click a second time, it deletes de last row, and creates a new table. How can i create a new row, with the new Data?
This is my code:

if (e.getSource()==sale)
    {
        int tempcod=0,tempcant=0; //tempcod is the code of the product,
       temocant is the number of products sold

    final DefaultTableModel model = new DefaultTableModel();

        model.addColumn("Product");
        model.addColumn("Price");

        try
        {
        tempcod=Integer.parseInt(cod.getText());
        tempcant=Integer.parseInt(quantity.getText());
        }
        catch(NumberFormatException a)
        {
            JOptionPane.showMessageDialog(null, "Invalid Number");
        }

        for (int j=0;j<nulo; j++) //nulo is the number of items at sale
        {

            if (tempcod==codigo[j]) //id the code i wrote exist in 
                                      the list of products
            {
                for (int k=0; k<nulo; k++)
                {
                    if (tempcod==ventaActual[0][k])
                    {
                        ventaActual[1][k]+=tempcant;
                    }
                    else
                    {
                    ventaActual[0][k]=tempcod;
                    ventaActual[1][k]=tempcant;
                    }
                }

                model.insertRow(model.getRowCount(), new Object[]{item[j],price[j]*tempcant});//this line creates the row of the table.
          //item[] is the name of the item, price[] is the price of the item
                JTable Lista= new JTable(model);
                lista1=new JScrollPane(Lista);
                lista1.setBounds(170,150,200,200);
                lista1.setEnabled(false);
                lista1.setVisible(true);
                this.add(lista1);

                a+=(tempcant*precio[j]);
                String b=Integer.toString(a);
                tot.setText(b);
                ventaInforme=ventaActual;
            }
            else
            {
                cod.setText(null);
                cantidad_n.setText(null);
            }
        }
    }
  • 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-27T03:55:43+00:00Added an answer on May 27, 2026 at 3:55 am

    Your call to model.insertRow should insert a row into the table and fire the necessary events for the table to update itself. However, you need to get the existing model from the existing table, and then update that model.

    e.g. DefaultTableModel model = (DefaultTableModel)myTable.getModel();

    You should probably also get rid of the code that creates and adds a new table to your container, unless that’s what you want.

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

Sidebar

Related Questions

I have a button and on click of that i show a popup which
Basically is to click button to generate table row, then click minus button to
Typical jQuery over-use: $('button').click(function() { alert('Button clicked: ' + $(this).attr('id')); }); Which can be
I am using $(.button).on(click, function(){ }); to click to a button which is on
hi i am doing one app here when i click button that time i
I have an AuthorizationServlet which is called when user click button in login page.
I have one button. When i click on this button, it will show one
I'm implementing a click button for my animation plugin, but I found a problem.
I am trying to use some action when I click button in navigation controller.
I have form area in my view. If I click button A , I

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.