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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:51:48+00:00 2026-06-02T03:51:48+00:00

I have the following situation: For ech tree node I have a different type

  • 0

I have the following situation:

the way I want to store an object inside my tree

For ech tree node I have a different type of image icon.

The way I actually set these icons is by overriding getTreeCellRendererComponent, verifying the user object (the title), and then painting the icon.

Else, set the icon to an object icon (for o3) because it does not have a stable name.

private final String OBJECTS, OBJECT, MATERIAL, DIMENSIONS, L, W, H,
        LEFT, RIGHT, FRONT, BACK, TOP, BOTTOM; //=...

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {

    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    node = (DefaultMutableTreeNode) value;
    String str = node.getUserObject().toString().toLowerCase();

    if (str.contains("objects")) {
        setIcon(new ImageIcon(OBJECTS));
    }
    else if (str.contains("components")) {
        setIcon(new ImageIcon(OBJECTS));
    }
    else if (str.contains("dimensions")) {
        setIcon(new ImageIcon(DIMENSIONS));
    }
    else if (str.contains("materials")) {
        setIcon(new ImageIcon(MATERIAL));

    }
    else if (str.contains("length")) {
        setIcon(new ImageIcon(L));
    }
    else if (str.contains("width")) {
        setIcon(new ImageIcon(W));
    }
    else if (str.contains("height")) {
        setIcon(new ImageIcon(H));
    }
    else if (node.getParent().toString().toLowerCase().contains("components") ||
             node.getParent().toString().toLowerCase().contains("objects")) {
        setIcon(new ImageIcon(OBJECT));
    }

    return this;
}

I am stuck at painting Materials’ children.
I know the order (up, down, L, R, front, bottom), but I need a way to identify the nodes.
I was thinking to get their parent and somehow identify them by their number in the childer list. Need help here.

  • 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-02T03:51:53+00:00Added an answer on June 2, 2026 at 3:51 am

    You have the problem to formulate the decision that maps an image/icon to the node.

    I suggest you use the strategy pattern so that you can change the way on how to find out which icon should be used for the node in question.

    You can then try different ways to solve the problem and also the routine does not get stuck with all the ifs and such.

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

Sidebar

Related Questions

I have the following situation: <input id=upload_trigger_btn type=file name=files[] multiple> <a type=submit class=button-normal-12px-ffffff href=#><span>Add
I have the following situation: Several applications in different machines are going to share
I have the following situation where a client class executes different behavior based on
I have the following situation: while (node != NULL && has_all_except) { ... }
I have the following situation: I set the beans (in applicationContext.xml) as follows: ...
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following situation. A main table and many other tables linked together with
I have following situation. In a constructor of a pseudo class I attach a
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //
I have following situation, String a=<em>crawler</em> <em> Yeahhhhh </em></a></h3><table; System.out.println(a.indexOf(</em>)); It returns the 11

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.