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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:45:22+00:00 2026-06-18T00:45:22+00:00

i am new to Stack overflow and looking for some help on a java

  • 0

i am new to Stack overflow and looking for some help on a java app i have been working on at college.

My questions is, how do I insert an integer from a Jtextfield (in external class) into a Jtable using a button action listener event.

My code is:

External class Button Code to insert a jtextfield integer to the table

   package banknew;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;



public class CheckingAccount extends BANKNEW
{

final JButton DepositAmount = new JButton("Deposit");  
final JTextField tAmount = new JTextField();

    public void CheckingAccount() {
        String title = "Checking Account";
        JFrame checkingAccount = new JFrame(title);

        checkingAccount.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        checkingAccount.setSize(400, 200);
        checkingAccount.setLocation(checkingAccount.getHeight() / 2, checkingAccount.getWidth() / 2);

        final JLabel error = new JLabel("");
        checkingAccount.add(error, BorderLayout.SOUTH);
        error.setVisible(true);
        error.setLocation(5, 600);


        JMenuItem file1 = new JMenuItem("Checking Account");
        JMenuItem file2 = new JMenuItem("Checking Accounts");
        JMenuItem file3 = new JMenuItem("Checking Accounts");
        JMenuItem file4 = new JMenuItem("Bank Account");
        JMenuItem file5 = new JMenuItem("Close");



        JMenu filemenu = new JMenu("File");
        filemenu.add(file1);
        filemenu.add(file2);
        filemenu.add(file3);
        filemenu.addSeparator();
        filemenu.add(file4);
        filemenu.addSeparator();
        filemenu.add(file5);

        JMenuBar menubar = new JMenuBar();
        menubar.add(filemenu);
        checkingAccount.setJMenuBar(menubar);
        BorderLayout border = new BorderLayout();
        filemenu.setLayout(border);
        checkingAccount.setVisible(true);





        /**
         * ****************************************
         * Create Second JPanel - Buttons & ComboBox .
 *****************************************
         */
        JPanel abuttons1 = new JPanel();
        checkingAccount.add(abuttons1);
        //abuttons1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        abuttons1.setBorder(BorderFactory.createTitledBorder(""));

        JButton Withdraw = new JButton("Withdraw");
        JLabel transBankName1 = new JLabel("Account Name:");
        JLabel transAmount = new JLabel("Amount:");


        final JTextField tBankName1 = new JTextField(20);
        final JComboBox AccountName = new JComboBox();
        AccountName.setEditable(false);
        AccountName.setMaximumSize(new java.awt.Dimension(100, 20));
        AccountName.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        transBankName1.setMaximumSize(new java.awt.Dimension(100, 20));
        transAmount.setMaximumSize(new java.awt.Dimension(100, 20));
        tAmount.setMaximumSize(new java.awt.Dimension(100, 20));
        tBankName1.setMaximumSize(new java.awt.Dimension(00, 20));

        abuttons1.setLayout(new GridLayout(5, 1, 5, 5));
        abuttons1.add(transBankName1);
        abuttons1.add(AccountName);
        abuttons1.add(transAmount);
        abuttons1.add(tAmount);

        abuttons1.add(Withdraw);
        abuttons1.add(DepositAmount);
        abuttons1.setLocation(0, 0);
        abuttons1.setSize(300,200);

         DepositAmount.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (table.getSelectedRow() > -1) {
                    // assuming from your code that you want to set the
                    // textfield's value at the table's selected row
                    try {
                        Integer amount = Integer.parseInt(tAmount.getText());
                        table.getModel().setValueAt(amount, table.getSelectedRow(), 4);
                    } catch (NumberFormatException nfe) {
                        // User did not provide a number.
                        // do nothing? show dialog? you name it!
                    }
                }
            }
        });
    }


    }
  • The External class has a GUI with the Textfield and ‘Deposit’ Button.
  • The Main Class has a GUI with a 5 column JTable

All i want to be able to do is have an external extended class with a Button, and on button click insert amount from local textfield into the main Jtable as shown in the code with the ‘abc’ table model.

I have searched google and stack overflow but most posts are related to SQL or database linkage.

If anyone can point me in the right direction, i would be very grateful.

Thanks

EDIT 2: Copy and paste the code and ill try and upload the main class, let me know once you have copied it…

  • 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-18T00:45:23+00:00Added an answer on June 18, 2026 at 12:45 am

    Am a bit unsure of the more global setup of your classes.
    But if the CheckingAccount is supposed to write to the table, it’ll need to be provided a reference to the table in its constructor.

    public class CheckingAccount {
        final JButton depositAmount = new JButton("Deposit");  
        final JTextField tAmount = new JTextField();
    
        //Provide the JTable to the CheckingAccount when you construct it!
        public CheckingAccount(final JTable table) {
            depositAmountButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if (table.getSelectedRow() > -1) {
                        // assuming from your code that you want to set the
                        // textfield's value at the table's selected row
                        try {
                            Integer amount = Integer.parseInt(textField.getText());
                            table.getModel().setValueAt(amount, table.getSelectedRow(), 4);
                        } catch (NumberFormatException nfe) {
                            // User did not provide a number.
                            // do nothing? show dialog? you name it!
                        }
                    }
                }
            });
        }
    }
    

    To learn a bit more about how to use Swing, take a look at the Oracle tutorials

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

Sidebar

Related Questions

I'm new to SOA (and to Stack Overflow too...) Some services and web applications
I'm looking at some code with this form: 1 package com.stackoverflow.java.questions; 2 import java.util.ArrayList;
I am new to Stack Overflow and Ruby on Rails. My problem is, when
I am very much new to stack overflow so I do apologize if I
I am new here and hope my first question meets stack overflow's requirements. I
I've been working writing fairly small applications and doing some maintenance work for some
I was looking through different blogs, sites and stack overflow for my answer. I
I've been looking into Varnish recently and doing some heavy Google searching. We've recently
Woot, first Stack Overflow post! I've been asked to work on a desktop application
I've read a couple of other questions/answers on stack overflow regarding this, but wanted

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.