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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:11:43+00:00 2026-06-15T01:11:43+00:00

I got such a trouble. I have an overlay database structure and use JTree

  • 0

I got such a trouble. I have an overlay database structure and use JTree to display the items. Here’s my simplified view of model:

public class MenuTreeModel implements TreeModel {
private MenuList ml;

public MenuTreeModel( MenuList ml ) {
    this.ml = ml;
}

@Override
public void addTreeModelListener(TreeModelListener l) {

}

@Override
public Object getChild(Object parent, int index) {
    if ( parent.getClass().hashCode() == MenuList.class.hashCode() ){
        return ((MenuList) parent).getStation(index);
    }
    if ( parent.getClass().hashCode() == MenuStations.class.hashCode() ){
        return ((MenuStations) parent).get(index);
    }
    return null;
}

@Override
public int getChildCount(Object parent) {
    if ( parent.getClass().hashCode() == MenuList.class.hashCode() ){
        return ((MenuList) parent).getSize();
    }
    if ( parent.getClass().hashCode() == MenuStations.class.hashCode() ){
        return ((MenuStations) parent).getSize();
    }
    return 0;
}

@Override
public int getIndexOfChild(Object parent, Object child) {
    if ( parent.getClass().hashCode() == MenuList.class.hashCode() ){
        return ((MenuList) parent).getIndexOf((MenuStations) child);
    }
    if ( parent.getClass().hashCode() == MenuStations.class.hashCode() ){
        return ((MenuStations) parent).getIndexOf((MenuCats) child);
    }
    return 0;
}

@Override
public Object getRoot() {
    return ml;
}

@Override
public boolean isLeaf(Object node) {
    return node.getClass().hashCode() == MenuCats.class.hashCode();
}

@Override
public void removeTreeModelListener(TreeModelListener l) {
    // TODO Auto-generated method stub

}

@Override
public void valueForPathChanged(TreePath path, Object newValue) {
    // TODO Auto-generated method stub

}

And when I remove something from ml or its inner items, the tree structure does not change. I couldn’t find any method like fireTreeModelChanged.

  • 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-15T01:11:44+00:00Added an answer on June 15, 2026 at 1:11 am

    You would only find a method fireTreeModelChanged() if your model extended a class containing such a method. But unlike TableModel, which has an associated AbstractTableModel containing fireXxx() methods, there is no such class for trees. Your best bet is to either use a DefaultTreeModel, or to define your own event firing methods.

    Of course, to be able to implement them, you would need to actually add listeners in your addTreeModelListener() method, instead of not doing anything.

    Another thing that should be changed in your code is your comparisons of hash codes. It makes no sense doing that. BTW, two different classes could have the same hash code. Just use

    parent.getClass().equals(MenuList.class)
    

    or

    parent instanceof MenuList
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i've a trouble with linq, i'll explain on example : i have a database
I have a database from which I want to query and display only that
having a little architectural trouble here. In C++, we have the notion of 'friends,'
I got such code at the end of the website for a pre-loader: <iframe
I've got such a function: void cleanup_module(void) { /* * Unregister the device */
I' ve got such a function static ssize_t read_mydevice(struct file *filp, char* buf, size_t
I've been doing a prototype in WPF without using MVVM. It's got to such
I've got a requirement such that, when a user logs in while completing a
I've got an enum defined as such: Private Enum AllowedMonthNumbers _1 _2 _3 _4
I've got quite a few SQL statements like such: SELECT foo FROM things WHERE

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.