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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:44:56+00:00 2026-05-26T10:44:56+00:00

I’m still struggling with a JTable that should be automatically updated. The situation is

  • 0

I’m still struggling with a JTable that should be automatically updated.

The situation is as follows:
I instantiate MyTable (extends JTable), and set it in my UI class (MyView). The MyTable class takes the UI class and an instance of the class that contains logic as parameters):

...
private JPanel createTablePanel() {
    tablePanel = new JPanel();
    myTable = new MyTable(this,mymeth);
    setMyTable(myTable);
    JScrollPane scrollPane = new JScrollPane(getMyTable());
    tablePanel.add(scrollPane);
    return tablePanel;
}

MyTable itself looks like below. An extension of AbstractTableModel (MyTableModel) is set to it. An extension of TableModelListener is set to the model. And finally an extension of ListSelectionListener is set to the model’s SelectionModel.

public class MyTable extends JTable implements TableModelListener
{

public MyTable(MyView myView, MyMethods mymeth)
{

    AbstractTableModel tableModel = new MyTableModel(mymeth);
    setModel(tableModel);
    getModel().addTableModelListener(new MyTableModelListener());
    setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    setCellSelectionEnabled(true);
    getColumnModel().getSelectionModel().addListSelectionListener(new MyTableSelectionListener(this, mymeth, myView));
    setPreferredScrollableViewportSize(this.getPreferredSize());

}

}

Let’s have a quick look at the model’s constructor.

public MyTableModel(MyMethods mymeth) {
    dataObject = new MyData(mymeth);
    myData = dataObject.getMyData();
    colTitles = dataObject.getColTitles();
}

MyData compiles the data for the table: A Vector<Vector<Object>>, that consists of three Vector<Object>s (the table data) and a String[] (The column titles). The data itself comes from a graph via mymeth, the logic class’ instance.

Whenever a table column is clicked, a popup (i.e. JOptionPane) object is instantiated, which presents a selection of values for the 3rd row in the selected column. The user chooses a value and the value is set to the data model. Note the way the table is updated after that.

public MyOptionPane(int i, MyMethods mymeth, MyView myView) {
    this.view = myView;
    String sourceString = mymeth.getSourceString(i); // Gets a String from a
String[]. In this Array, the order is the same as in the table.
    String tag = null;
    tag = (String) JOptionPane.showInputDialog(this, "Choose a tag for \"" + sourceString + "\"", "String tagging" , JOptionPane.PLAIN_MESSAGE, null, myView.getTags().toArray(), myView.getTags().get(0));
    mymeth.setTag(i, tag);

    // This is where fireTableDataChanged() didn't work, but this did
            MyTableModel model = new MyTableModel(mymeth); // New model instance
    view.getMyTable().setModel(model); // reset new model to table
}

This works. However, from what I’ve read I shold be able to simply call fireTableDataChanged() on the model and the table should update itself. However, this doesn’t work. User kleopatra has commented to an answer in a previous post:

do not call any of the model’s fireXX methods from any code external to the model.
Instead implement the model to do so when anything changed

So: Can I call fireTableDataChanged() within such a structure at all? And if so, where and how?

Thanks in advance for all pieces of enlightenment!

  • 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-26T10:44:57+00:00Added an answer on May 26, 2026 at 10:44 am

    from what I’ve read I shold be able to simply call fireTableDataChanged() on the model and the table should update itself

    Your program doesn’t invoke the fireXXX methods on the model. The TableModel itself is responsible for invoking these methods whenever any of the data in the model is changed. Look at the Creating a Table Model example from the Swing tutorial. The setValueAt(…) method shows how to invoke the appropriate fireXXX method.

    If you create a completely new TableModel, then you need to use the setModel() method.

    Kleopatra’s comment was that all fireXXX methods showed be invoked from within the TableModel class itself. If you want to understand how this is done, then take a look at the source code for the DefaultTableModel. If has example of when you would invoke the fireTableDataChanged() method along with the other fireXXX methods.

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

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
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 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
I need a function that will clean a strings' special characters. I do NOT
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

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.