Jump to content

NetBeans GUI editor (drag/drop) and JTable data issue

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Ceryph

Ceryph

    Newbie

  • Members
  • Pip
  • 2 posts
OK, so I've been trying to do some searching and I'm getting a bit confused.
It's hard to find examples that address issues specifically when using the prebuilt components in NetBeans.

I have added a Table to my GUI. I then went to the "model" property and removed the rows and one of the columns and then customized my column names.

There is a single button that affects all of this code. This is a school project, so it's rather simple. I'm just having trouble getting my JTable to be updated after I add new rows.
I've tried various things people have mentioned on forums, but just can't seem to get my Table to update. When I run my program, I don't get any errors when I click on my button, it just calculates the Monthly Payment, and does nothing with the Table. I'm hoping I'm even updating a row properly and that I'm simply having troubles with the Table displaying it.

So, here is my code with the lines bolded that are related to the table; hopefully someone can point in me in the correct direction:


[B]import javax.swing.table.DefaultTableModel;[/B]


    private void btnCalculateActionPerformed(java.awt.event.ActionEvent evt) {                                             

        double principleValue = 200000.00;

        

        double[] APR = {5.35, 5.5, 5.75};

        int[] termLength = {7, 15, 30};

        

        int i = cboLoans.getSelectedIndex();


        double interestRate = APR[i] / 100 / 12;        

        int notePeriod = termLength[i] * 12;

        

        double monthlyPayment = calculateMonthlyPayment(principleValue, interestRate, notePeriod);

        

        this.txtMonthlyPayment.setText(Currency.format(monthlyPayment));

        

        //Initialize values for Amortization Table

        double loanBalance = notePeriod * monthlyPayment;

        double principalBalance = principleValue;

        double interestBalance = loanBalance - principalBalance;

        double totalPrincipalPaid = 0;

        double totalInterestPaid = 0;

        

        [B]DefaultTableModel model = (DefaultTableModel) tblAmortization.getModel();[/B]

        

        for (int x = 1; x < notePeriod + 1; x++) {

            //The portion of the payment that goes to interest is based on the remaining principal balance.

            double interestPaidThisMonth = interestRate * principalBalance;


            //The rest of the payment goes to principal.

            double principalPaidThisMonth = monthlyPayment - interestPaidThisMonth;


            //Update the remaining balances and total paid values

            totalPrincipalPaid += principalPaidThisMonth;

            principalBalance -= principalPaidThisMonth;

            totalInterestPaid += interestPaidThisMonth;

            interestBalance -= interestPaidThisMonth;         

            loanBalance -= monthlyPayment;


            //Add values to JTable

            [B]Object[] newRowData = {x, "$" + Currency.format(totalInterestPaid), "$" + Currency.format(loanBalance)};[/B]

            [B]model.addRow(newRowData);[/B]

            

        }

        [B]tblAmortization.setModel(model);[/B]

    }   


Edited by Ceryph, 15 August 2011 - 07:46 PM.


#2
Ceryph

Ceryph

    Newbie

  • Members
  • Pip
  • 2 posts
Resolved at a forum that actually responds.

#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
With such attitude I'll make sure I never respond on your questions. Ever.

#4
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP

Ceryph said:

Resolved at a forum that actually responds.

Wow just because nobody responded in the time you needed doesn't mean anybody would never respond.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users