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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:49:08+00:00 2026-05-16T05:49:08+00:00

I’m Using Camick’s ListTableModel and RowTableModel from here http://tips4java.wordpress.com/2009/03/12/table-from-database/ However, the JTable is not

  • 0

I’m Using Camick’s ListTableModel and RowTableModel from here http://tips4java.wordpress.com/2009/03/12/table-from-database/

However, the JTable is not showing up. Does anyone know why? I’m not getting any errors.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

public class AddressBook {

    JLabel name, address, phone, email;
    JTextField nameField, addressField, phoneField, emailField;
    JButton addPerson, addEntry, cancelEntry;
    JTable table;
    ListTableModel model;
    JDialog addEntryDialog;
    String[] headings = {"Name", "Address", "Phone #", "Email"};

    AddressBook() {
        try {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        } catch (ClassNotFoundException e) {
            System.out.println(e);
        }

        try {
            Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/AddressBook", "addressbook", "addressbook");
            Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

            ResultSet rs = stmt.executeQuery("SELECT * FROM APP.ADDRESSBOOK");
            ListTableModel model = ListTableModel.createModelFromResultSet(rs);

            rs.close();
            //resultset.close();
            stmt.close();
            con.close();

        } catch(SQLException e){
            System.err.println(e);
        }

        JFrame frame = new JFrame("Address Book");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(500, 500);
        frame.getContentPane().setLayout(new FlowLayout());

        ButtonListener listener = new ButtonListener();

        addPerson = new JButton("New Entry");
        addPerson.addActionListener(listener);

        table = new JTable(model);
        JScrollPane scroll = new JScrollPane(table);
        scroll.setPreferredSize(new Dimension(500, 490));

        //Add a person Dialog

        name = new JLabel("Name:");
        address = new JLabel("Address:");
        phone = new JLabel("Phone:");
        email = new JLabel("Email:");

        nameField = new JTextField(8);
        addressField = new JTextField(8);
        phoneField = new JTextField(8);
        emailField = new JTextField(8);

        addEntry = new JButton("Save");
        addEntry.addActionListener(listener);
        cancelEntry = new JButton("Cancel");
        cancelEntry.addActionListener(listener);

        addEntryDialog = new JDialog(frame, "Add a Person");
        addEntryDialog.setSize(190, 300);
        addEntryDialog.getContentPane().setLayout(new FlowLayout());

        addEntryDialog.getContentPane().add(name);
        addEntryDialog.getContentPane().add(nameField);
        addEntryDialog.getContentPane().add(address);
        addEntryDialog.getContentPane().add(addressField);
        addEntryDialog.getContentPane().add(phone);
        addEntryDialog.getContentPane().add(phoneField);
        addEntryDialog.getContentPane().add(email);
        addEntryDialog.getContentPane().add(emailField);
        addEntryDialog.getContentPane().add(cancelEntry);
        addEntryDialog.getContentPane().add(addEntry);

        //end of Add a person dialog

        frame.getContentPane().add(addPerson);
        frame.getContentPane().add(table);
        frame.setVisible(true);
    }

    class ButtonListener implements ActionListener {

        public void actionPerformed(ActionEvent event) {
            JButton source = (JButton) event.getSource();

            if (source == addPerson) {
                addEntryDialog.setVisible(true);
            }
            if (source == addEntry) {
                //add to db
            }
            if (source == cancelEntry) {
                addEntryDialog.setVisible(false);
            }
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                new AddressBook();
            }
        });
    }
}
  • 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-16T05:49:09+00:00Added an answer on May 16, 2026 at 5:49 am

    Taking a second look at your code the problem is that you have defined the “model” variable as a class variable and an instance variable. The instance variable contains the data from the ResultSet. The class variable which is used to to create the table, is null. The code should be:

    //ListTableModel model = ListTableModel.createModelFromResultSet(rs); 
    model = ListTableModel.createModelFromResultSet(rs); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.