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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:11:58+00:00 2026-05-10T23:11:58+00:00

I have a JTable with a custom TableModel called DataTableModel . I initialized the

  • 0

I have a JTable with a custom TableModel called DataTableModel. I initialized the table with a set of column names and no data as follows:

books = new JTable(new DataTableModel(new Vector<Vector<String>>(), title2)); JScrollPane scroll1 = new JScrollPane(books); scroll1.setEnabled(true); scroll1.setVisible(true); JSplitPane jsp1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scroll1, scroll2); JSplitPane jsp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, inventory, jsp1); myPanel.add(jsp2, BorderLayout.CENTER); 

I later want to update books with a set of data, and use the following:

DataTableModel d = (DataTableModel)books.getModel(); d.setValues(bookList); books.setModel(d); 

where bookList is a Vector<Vector<String>> that definitely has data. However, although all this code is being executed, it is not displaying on the screen. The code for the setValues() method is:

public void setValues(Vector<Vector<String>> v) {     values = v;     fireTableDataChanged(); } 

Am I missing something here?

The class and methods for my DataTableModel are (these methods are all implemented to return correct results):

public class DataTableModel extends AbstractTableModel {     public DataTableModel(Vector<Vector<String>> v, Vector<String> c) {}      public int getColumnCount() {         if (values != null && values.size() > 0)             return values.elementAt(0).size();         else             return 0;     }      public int getRowCount() {         if (values != null && values.size() > 0)             return values.size();         else             return 0;     }      public Object getValueAt(int arg0, int arg1) {}     public void setValues(Vector<Vector<String>> v) {}     public Vector<Vector<String>> getValues() {}     public void setColumnNames(Vector<String> columns) {}     public String getColumnName(int col) {} } 
  • 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. 2026-05-10T23:11:59+00:00Added an answer on May 10, 2026 at 11:11 pm

    Have you implemented the other methods for TableModel? If so, how does your implementation look? Maybe you should post your table model code to let us inspect it?

    BTW: My main error when implementing TableModel was to override getRowCount() and getColumnCount() to return 0. This will tell the table that there is no data to display…

    EDIT: So you seem to be using something like an AbstractTableModel or a DefaultTableModel, right? Have you overridden some of the methods?

    EDIT 2: You should call fireTableStructureChanged instead of fireTabeDataChanged(), because initially your table model is returning 0 for getColumnCount().

    EDIT 3: To further optimize your model you should consider returning a fixed value for getColumnCount() if you have data that has the same number of columns every time. Then you can call the fireTabeDataChanged() which just loads the new data instead of completely building up the table and data (fireTableStructureChanged()) every time.

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

Sidebar

Ask A Question

Stats

  • Questions 107k
  • Answers 107k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Billing monthly is assumed to be 12 times per year,… May 11, 2026 at 9:08 pm
  • Editorial Team
    Editorial Team added an answer You cannot expect to parse a date with a SimpleDateFormat… May 11, 2026 at 9:08 pm
  • Editorial Team
    Editorial Team added an answer Ye Olde New Answer Here are some Stack Overflow questions… May 11, 2026 at 9:07 pm

Related Questions

I have a JTable with a set of uneditable cells and I want all
I'm writing a custom swing component (something completely new, but think JTree or JList).
I'm developping a small UML Class editor in Java, mainly a personal project, it
Is there a relatively simple way to change all the data in a JTable?

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.