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

  • Home
  • SEARCH
  • 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 9175467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:55:04+00:00 2026-06-17T16:55:04+00:00

I need some help with a project that i have been set. I am

  • 0

I need some help with a project that i have been set. I am creating a small addressbook program in java. I have got the user interface sorted and i am now working on adding information into a JTable from an inputDialog.

Here is my addressbook user Interface.

    import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JPanel;

public class AddressBookGUI {

    private static final int FRAME_WIDTH = 400;
    private static final int FRAME_HEIGHT = 100;
    private static JTable table;

    public static void main(String[] args) {

        JFrame frame = new JFrame();
        final JFrame addPersonFrame = new JFrame();
        frame.setSize(768, 300);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //
        JButton addButton = new JButton("Add");
        addButton.setBounds(10, 228, 89, 23);
        addButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                JOptionPane.showInputDialog("First Name: ");
                JOptionPane.showInputDialog("Last Name: ");
                JOptionPane.showInputDialog("Address: ");
                JOptionPane.showInputDialog("Town: ");
                JOptionPane.showInputDialog("County: ");
                JOptionPane.showInputDialog("Post Code: ");
                JOptionPane.showInputDialog("Phone Number: ");

            }
        });
        frame.getContentPane().setLayout(null);
        frame.getContentPane().add(addButton);

        JButton editButton = new JButton("Edit");
        editButton.setBounds(109, 228, 89, 23);
        frame.getContentPane().add(editButton);

        JButton delButton = new JButton("Delete");
        delButton.setBounds(208, 228, 89, 23);
        frame.getContentPane().add(delButton);
        // Declare new menuBar and menuItems
        JMenuBar mainMenuBar = new JMenuBar();
        JMenu fileMenuBar = new javax.swing.JMenu();
        JMenuItem newFileMenuBar = new JMenuItem();
        JMenuItem openFileMenuBar = new JMenuItem();
        JMenuItem saveFileMenuBar = new JMenuItem();
        JMenuItem printFileMenuBar = new JMenuItem();
        JMenuItem quitFileMenuBar = new JMenuItem();
        JMenuItem editMenuBar = new JMenu();
        JMenuItem editPersonsEditMenuBar = new JMenuItem();
        JMenuItem sortNameEditMenuBar = new JMenuItem();
        JMenuItem sortPostcodeEditMenuBar = new JMenuItem();
        JMenuItem helpMenuBar = new JMenu();
        JMenuItem aboutHelpMenuBar = new JMenuItem();

        JMenuBar menuBar = new JMenuBar();
        menuBar.setBounds(0, 0, 742, 21);
        frame.getContentPane().add(menuBar);

        JMenu mnFile = new JMenu("File");
        menuBar.add(mnFile);
        // Declares and adds items to the menu
        JMenuItem menuItemNew = new JMenuItem("New");
        mnFile.add(menuItemNew);

        JMenuItem menuItemOpen = new JMenuItem("Open");
        mnFile.add(menuItemOpen);

        JMenuItem menuItemSave = new JMenuItem("Save");
        mnFile.add(menuItemSave);

        JMenuItem menuItemSaveAs = new JMenuItem("Save As..");
        mnFile.add(menuItemSaveAs);

        JMenuItem menuItemPrint = new JMenuItem("Print");
        mnFile.add(menuItemPrint);

        JMenuItem menuItemQuit = new JMenuItem("Quit");
        menuItemQuit.addActionListener(new exitApp());
        mnFile.add(menuItemQuit);

        JMenu menuEdit = new JMenu("Edit");
        menuBar.add(menuEdit);

        JMenuItem menuItemEditSelectedPerson = new JMenuItem(
                "Edit Selected Person");
        menuEdit.add(menuItemEditSelectedPerson);

        JMenuItem menuItemSortByName = new JMenuItem("Sort By Name");
        menuEdit.add(menuItemSortByName);

        JMenuItem menuItemSortPostCode = new JMenuItem("Sort By Post Code");
        menuEdit.add(menuItemSortPostCode);

        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setBounds(10, 32, 732, 151);
        frame.getContentPane().add(scrollPane);

        table = new JTable();
        table.setModel(new DefaultTableModel(new Object[][] {
                { "", null, "", "", "", null, null },
                { null, null, null, null, null, null, null },
                { null, null, null, null, null, null, null },
                { null, null, null, null, null, null, null },
                { null, null, null, null, null, null, null },
                { null, null, null, null, null, null, null }, }, new String[] {
                "First Name", "Last Name", "Addesss", "Town", "County",
                "Post Code", "Phone Number" }));
        scrollPane.setViewportView(table);

        frame.setVisible(true);

    }

    static class exitApp implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent event) {
            // closes the application
            System.exit(0);

        }

    }

}

If some one could help me that would be great.

Thanks

  • 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-17T16:55:05+00:00Added an answer on June 17, 2026 at 4:55 pm

    If you need to pass the entered data from the JOptionPane to the JTable then first get the data and the UI and add it to the JTable.

    If you are storing each row as an Object then use the method,

    model.addRow(..);
    

    If you are storing each value individually then use the method,

    // value here is your input.
    setValueAt(value, rowIndex, columnIndex);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with a work project I have been assigned. At the
Seems like i need some help with a project. I have a routine ,
I have been having some issues with django-haystack and need some help. I run
I need some help with my project. I've created a Custom Adapter, since I
I'm experiencing some difficulties configuring our project with Maven and need some help :)
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview
I am developing a project that lately have been taking off with increased popularity.
I need some help with my Makefile for a project. The source directory looks

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.