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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:17:48+00:00 2026-06-03T16:17:48+00:00

I’m desperately trying to convince my JTable to refresh when I change its data.

  • 0

I’m desperately trying to convince my JTable to refresh when I change its data. The data are stored in a global singleton, TreeSet, that I’m working with. Whenever the TreeSets data is altered, an event is fired to refresh the TableModel. For test purposes, I replaced this by a simple Timer firing events.

Each time an event is fired, an element from the TreeSet is removed to simulate changes in the data. The event fires and the TableClass receives it and processes it as expected, but when it comes to refreshing nothing happens. I tried to create a new TableModel each time an event occurs and set it to the global table. The changes to the singleton TreeSet are made but nothing happens to the JTable.

public class TreeTableObj implements ActionListener{
public JTable table ;

public TreeTableObj(){
    MyTableModel myModel = new MyTableModel(getValuesOfTreeSet(), getTreeSetRows());

    table = new JTable( myModel){ //some rendering };

    table.setAutoCreateRowSorter(true);
    }

    class MyTableModel extends AbstractTableModel {
        private String[] columnNames;
        private Object[][] data ;


        public MyTableModel(Object[][] data, String[] columnNames){
            this.data = data;
            this.columnNames = columnNames;
            System.out.println("Model created");
        }

        public int getColumnCount() {
            return columnNames.length;
        }

        public int getRowCount() {
            return data.length;
        }

        public String getColumnName(int col) {
            return columnNames[col];
        }

        public Object getValueAt(int row, int col) {
            return data[row][col];
        }

        public void setData(Object[][] data){
            this.data = data;
            fireTableDataChanged();
        }


        public Class getColumnClass(int c) {
            return getValueAt(0, c).getClass();
        }


        public boolean isCellEditable(int row, int col) {
            if (col < 2) {
                return false;
            } else {
                return true;
            }
        }


        public void setValueAt(Object value, int row, int col) {
            if (true) {
                System.out.println("Setting value at " + row + "," + col
                                   + " to " + value
                                   + " (an instance of "
                                   + value.getClass() + ")");
            }

            data[row][col] = value;
            fireTableCellUpdated(row, col);

            if (true) {
                System.out.println("New value of data:");
                printDebugData();
            }
        }

        private void printDebugData() {
            int numRows = getRowCount();
            int numCols = getColumnCount();

            for (int i=0; i < numRows; i++) {
                System.out.print("    row " + i + ":");
                for (int j=0; j < numCols; j++) {
                    System.out.print("  " + data[i][j]);
                }
                System.out.println();
            }
            System.out.println("--------------------------");
        }
    }

    public void refreshTableModel(){
        FlightsTreeSet.getInstance().remove(FlightsTreeSet.getInstance().first());
        table.setModel(new MyTableModel(getValuesOfTreeSet(), getTreeSetRows()));
        }

    public void actionPerformed(ActionEvent arg0) {
        refreshTableModel();    
    }
}

Any help would be appreciated!

[EDIT1]

I am getting closer to the problems Core:
I found out that the table which is displayed in the JFrame holds another reference as the one that I change. I made all changes visible and they apply to the Model.

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

    I found the problem. And leaving the answer here to be found by others…
    After realizing that the displayed JTable and the one that I was editing hold different references (see [EDIT1]) I found out that I was creating two different Objects of the JTable. One to be displayed and the other one in main() to become an ActionListener. The Listener received the Events and did the changes but the other one never noticed that anything was happening.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.