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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:46:13+00:00 2026-05-13T14:46:13+00:00

I have a tree and a table on my panel, when I click the

  • 0

I have a tree and a table on my panel, when I click the tree node, the table needs to change at the same time, but it doesn’t. I search online and read the Java tutorial and didn’t find any solutions. From some posts I think I need to use fireTableStruetureChanged(), but it just doesn’t work in my code. Could anyone help me out of this? The following is the code. Thanks a ton!

public class tableStructureChange extends JFrame implements ... {
.....

/ //columnNames is a public variable, because I need to change the columns later
columnNames = new String[] {"col1","col2"}; */
data = new String[][]{
{"Mary", "Campione"},
{"Alison", "Huml"}, };

table = new JTable(new MyTableModel());
table.setAutoCreateColumnsFromModel( false );

feedback = new JScrollPane(table);  //feedback is the bottom panel

…

}

//the following class is the problem, i need the table to be reloaded
//when the class is called, but the table doesn't change at all

public void displayFeedback(String tempString) {

//create table for bottom panel
columnNames = new String[] {"col3","col4", "col5"};
String[][] data = new String[][]{
{"Mary", "Campione", "us"},
{"Alison", "Huml", "canada"}, };
//table = new JTable(data, columnNames);
//fireTableStructureChanged();   //this is the problem part

}

// my table model
class MyTableModel extends AbstractTableModel {
String[] columnNames = new String[] {“col1″,”col2”};

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];

}

}

…
}

  • 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-13T14:46:13+00:00Added an answer on May 13, 2026 at 2:46 pm

    In your method displayFeedback you seem to be hoping to replace the JTable object and have the display change to reflect what is selected in the JTree above. Instead of replacing what is in the View object, you should focus your effort on updating the Model, in this case, the AbstractTableModel subclass that you have created. There are a couple ways you can do that, but for a brute force proof of concept, you could do something like the following:

    • add a constructor to MyTableModel that takes a 2 dimensional array of data
    • in displayFeedback, create a new instance of MyTableModel that has new data relevant to the tree node that was selected.
    • call setModel on your global table variable.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in my database which stores a tree structure. Here are
I have a table in SQL server that has the normal tree structure of
So if I have to choose between a hash table or a prefix tree
I have tree control object created using CTreeCtrl MFC class. The tree control needs
Let's just say I have tree in my table called page: Foo -- Bar
I have a parent/child table (simple tree) table structure (ID, ParentID), where I want
I have content management system application that uses a polymorphic tree table as the
I have a tree-style database with the following structure: Table fields: NodeID int ParentID
So I have a table that's basically a tree. Each row has a parent
I have a table with 300K rows and b-tree index on operator field. While

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.