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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:36:09+00:00 2026-05-31T10:36:09+00:00

i made a class where i create my jtable. I have some issues because

  • 0

i made a class where i create my jtable. I have some issues because when i try to update it, it does not work (nothing happens – i think the way i am trying to update it is wrong?). What am i doing wrong?

class tableClass
{
    public Vector rowData = null; 
    public Vector columnNames = null; 
    private JTable jTable; 
    DefaultTableModel model;

    public tableClass(JPanel jPanel, Vector rowDataInput, Vector columnNamesInput)
    {       
        rowData = rowDataInput; 
        columnNames = columnNamesInput;

        jTable = new JTable(rowData, columnNames);
        jTable.setFillsViewportHeight(true);

        JScrollPane jScrollPane = new JScrollPane(jTable);
        jScrollPane.setPreferredSize(new Dimension(300, 100));
        jPanel.add(jScrollPane,BorderLayout.CENTER);
    }

    public void updateTable(Vector rowDataInput)
    {
        rowData = rowDataInput;  
        model =(DefaultTableModel)jTable.getModel();  
        model.fireTableDataChanged();
    }
}
  • 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-31T10:36:10+00:00Added an answer on May 31, 2026 at 10:36 am

    rowData is given to the JTable in the constructor. Then in updateTable you simply update the rowData field in your TableClass. Therefore neither the JTable nor its TableModel knows anything about your changes. You need to update the table’s model in updateTable.

    In other words, when you update rowData in updateTable you are not updating the same rowData object you passed into the JTable in your constructor.

    The below class is functionally the same as your class. Does this make it clearer why what you’re doing has no effect? You see, rowData is in no way shared by TableClass and the JTable. And it shouldn’t be – you should be updating the TableModel. You can implement your own TableModel and update that object with your changes.

    class tableClass
    {
        public Vector columnNames = null; 
        private JTable jTable; 
        DefaultTableModel model;
    
        public tableClass(JPanel jPanel, Vector rowDataInput, Vector columnNamesInput)
        {       
            Vector rowData = rowDataInput; 
            columnNames = columnNamesInput;
    
            jTable = new JTable(rowData, columnNames);
            jTable.setFillsViewportHeight(true);
    
            JScrollPane jScrollPane = new JScrollPane(jTable);
            jScrollPane.setPreferredSize(new Dimension(300, 100));
            jPanel.add(jScrollPane,BorderLayout.CENTER);
        }
    
        public void updateTable(Vector rowDataInput)
        {
            Vector rowData = rowDataInput;  
            model =(DefaultTableModel)jTable.getModel();  
            model.fireTableDataChanged();
        }
    }
    

    You could change your code as follows to prove that the changes work. Note that i’m not advocating this approach – you should really implement your own TableModel, but simply showing you how to change the underlying model itself and therefore see the changes take place in the JTable on-screen.

    EDIT As this answer was accepted, and following comments from @kleopatra and using @Adam’s answer (+1) i’ve update the below code to show how to update the entire data Vector or Vectors in updateTable. I still would not do it like this in production code, but at least this is functionally correct and closer to the OPs question.

    class MyTable {
        private Vector columnNames = null; 
        private JTable jTable;
    
        public tableClass(JPanel jPanel, Vector rowDataInput, Vector columnNamesInput) {
            // ...
            jTable = new JTable(rowData, columnNames);
            // ...
        }
    
        public void updateTable(Vector rowDataInput) {
            model =(DefaultTableModel)jTable.getModel();
    
            // Now actually update the model with your new data:
            model.setDataVector(rowDataInput, columnNames);
        }
    }
    

    As i said, this isn’t a good way to do it, but i’m just trying to show you why what you’re doing is not working. 🙂

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

Sidebar

Related Questions

I have made an class which conforms to the NSCoding protocol and does all
I have made a Java class where I have defined a constructor and some
My question is, In my code I have made a JTable in main class.
How can I create a new Exception different from the pre-made types? public class
I am learning C++ and I have a question. I made a class in
I made a music class that will play a song. I have made onResume
I'm cleaning up some code, and I have a class with an entity that
OK so I have made a class called Courses with private member functions courseName,
I have a problem using a class of made of structures. Here's the basic
I am attempting to create my own custom TableModel for my JTable (because I

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.