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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:16:16+00:00 2026-05-27T12:16:16+00:00

I have designed the following tree structure: function tree import javax.swing.* import javax.swing.tree.*; [I,map]

  • 0

I have designed the following tree structure:

function tree
import javax.swing.*
import javax.swing.tree.*;
[I,map] = checkedIcon;
javaImage_checked = im2java(I,map);
[I,map] = uncheckedIcon;
javaImage_unchecked = im2java(I,map);

% javaImage_checked/unchecked are assumed to have the same width
iconWidth = javaImage_unchecked.getWidth;

% create top node
root = uitreenode('v0','root', 'Results',[], 0);
% create children with checkboxes
Node1 = uitreenode('v0','Node1', 'Position', [], false);
root.add(Node1);
Node11 = uitreenode('v0','Node11', 'Cartesians Coordinates', [], true);
Node11.setIcon(javaImage_checked);
Node1.add(Node11);
Node12 = uitreenode('v0','Node12', 'Spherical Coordinates', [], true);
Node12.setIcon(javaImage_unchecked);
Node1.add(Node12);
Node2 = uitreenode('v0','Node2', 'Velocity', [], false);
root.add(Node2);
Node3 = uitreenode('v0','Node3', 'Acceleration', [], false);
root.add(Node3);

% set treeModel
treeModel = DefaultTreeModel(root);

% create the tree
[tree, container]= uitree('v0');
tree.setModel(treeModel);
% make root the initially selected node
tree.setSelectedNode(Node11);

 function [I,map] = checkedIcon()
    I = uint8(...
        [1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0;
         2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,1;
         2,2,2,2,2,2,2,2,2,2,2,2,0,2,3,1;
         2,2,1,1,1,1,1,1,1,1,1,0,2,2,3,1;
         2,2,1,1,1,1,1,1,1,1,0,1,2,2,3,1;
         2,2,1,1,1,1,1,1,1,0,1,1,2,2,3,1;
         2,2,1,1,1,1,1,1,0,0,1,1,2,2,3,1;
         2,2,1,0,0,1,1,0,0,1,1,1,2,2,3,1;
         2,2,1,1,0,0,0,0,1,1,1,1,2,2,3,1;
         2,2,1,1,0,0,0,0,1,1,1,1,2,2,3,1;
         2,2,1,1,1,0,0,1,1,1,1,1,2,2,3,1;
         2,2,1,1,1,0,1,1,1,1,1,1,2,2,3,1;
         2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
         2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,1;
         2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,1;
         1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1]);
     map = [0.023529,0.4902,0;
            1,1,1;
            0,0,0;
            0.50196,0.50196,0.50196;
            0.50196,0.50196,0.50196;
            0,0,0;
            0,0,0;
            0,0,0];
  end

  function [I,map] = uncheckedIcon()
     I = uint8(...
       [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1;
        2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1;
        2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,1;
        2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,1;
        1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1]);
     map = ...
      [0.023529,0.4902,0;
       1,1,1;
       0,0,0;
       0.50196,0.50196,0.50196;
       0.50196,0.50196,0.50196;
       0,0,0;
       0,0,0;
       0,0,0];
  end

  end

I would like to able to show an additional icon (on the right of the checked/unchecked icon and on the left of the nodes names). A solution that I have thought is replacing the name of the node with a jLabel component.

icon2 = javax.swing.ImageIcon('image.jpg');
jLabel = javax.swing.JLabel('Cartesian Coordinates');
jLabel.setIcon(icon2);
Node11.setName(jLabel);

However, the above code does not work. I also have tried to add a jLabel component to a treenode without success. I have even tried to modify the property ‘setIcon’ of a DefaultCheckBoxNode but this component has not that property. So, I asked myself if there is some solution for my problem.

  • 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-27T12:16:17+00:00Added an answer on May 27, 2026 at 12:16 pm

    You could create an icon that is a combination of the two icons, drawn side by side, and set that icon on the tree node. I am not sure if this is possible to do using just the MATLAB API, but my understanding is that you can construct and work with Java objects directly in MATLAB, so it should be possible either way.

    It appears the setIcon() method accepts a Java Image object, not an Icon object. Here is the general strategy for creating a composite image:

    1. Create a BufferedImage object with an appropriate width and height to hold both icons
    2. Get the Graphics2D object for the buffered image using BufferedImage.createGraphics()
    3. Draw each icon into the buffered image using Graphics2D.drawImage()

    This question and this question may be useful to you.

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

Sidebar

Related Questions

I have Designed the Javascript function My.js it contains following code My.js function display(){
I have the following regexp: (?P<question>.+(?<!\[\[)) It is designed to match hello world! in
I have designed the following class that should work kind of like a method
I have designed the following GUI in which there are an axes. I want
i have designed a model for a website with the following domain objects: Article
I have designed the header with the following CSS: .Navigation { height: 84px; background:
Given the following inheritance tree: I have a public class BaseForm : Form This
I have a text file. It is designed as following: #1{1,12,345,867} #2{123, 3243534, 2132131231}
I have the following code (VB.NET) which is designed to determine if a given
I have designed database tables (normalised, on an MS SQL server) and created a

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.