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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:33:36+00:00 2026-05-20T11:33:36+00:00

my problem is this I’m trying create a component that displays two tree side

  • 0

my problem is this

I’m trying create a component that displays two tree side by side. The two trees will generally be very similar but will probably have one or two differences. Where there is a difference, ie a branch in one but not in the other, I would like the tree without the branch to show an empty space for it, and for each of its missing children too.

So it might look something like

left tree        right tree
------------     -------------
+ Root           + Root
|                |
--Child A        --Child A
|                | 
--Child B        |
|                |
--Child C        --Child C

Its relatively straight forward to remove the text and icon for those rows that should be gaps using a custom renderer. However, this still leaves the horizontal line that connects a child to the parents vertical line. And this is my problem.

left tree        right tree
------------     -------------
+ Root           + Root
|                |
--Child A        --Child A
|                | 
--Child B        --  <--I want to remove this
|                |
--Child C        --Child C

It’s maybe bareable in this simple example but when the missing branch has children too I end up with lots of small lines connecting gaps.

A potential alternative I think is to create a one column JTreeTable for each tree and blank out the cells for the missing branches. Although this will mean that a portion of the vertical line will also be lost.

Any help, ideas or comments will be very much appriciated. Thanks.

  • 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-20T11:33:36+00:00Added an answer on May 20, 2026 at 11:33 am

    Consider the following:

    class ReticentTreeUI extends BasicTreeUI {
    
        private Set<Integer> hiddenRows = new HashSet<Integer>();
    
        public void hideRow(int row) {
            hiddenRows.add(row);
        }
    
        @Override
        protected void paintHorizontalPartOfLeg(Graphics g,
            Rectangle clipBounds, Insets insets, Rectangle bounds,
            TreePath path, int row, boolean isExpanded,
            boolean hasBeenExpanded, boolean isLeaf) {
            if (!hiddenRows.contains(row)) {
                super.paintHorizontalPartOfLeg(g, clipBounds, insets, bounds,
                    path, row, isExpanded, hasBeenExpanded, isLeaf);
            }
        }
    
        @Override
        protected void paintRow(Graphics g, Rectangle clipBounds,
            Insets insets, Rectangle bounds, TreePath path, int row,
            boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) {
            if (!hiddenRows.contains(row)) {
                super.paintRow(g, clipBounds, insets, bounds, path, row,
                    isExpanded, hasBeenExpanded, isLeaf);
            }
        }
    
        @Override
        protected void paintExpandControl(Graphics g, Rectangle clipBounds,
            Insets insets, Rectangle bounds, TreePath path, int row,
            boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) {
            if (!hiddenRows.contains(row)) {
                super.paintExpandControl(g, clipBounds, insets, bounds,
                    path, row, isExpanded, hasBeenExpanded, isLeaf);
            }
        }
    }
    

    Usage example:

        JTree tree = new JTree();
        ReticentTreeUI ui = new ReticentTreeUI();
        tree.setUI(ui);
        ui.hideRow(2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have another problem this time, i'm fetching json codes that will be used
Problem : This is a probably a very basic question, but how do I
I'm running in to the same problem this individual has . Specifically, I'm trying
In this problem, I have three (identically-structured) lists. Two have all numbers and the
This problem seems very simple to me, but I've been unable to fix it,
Before describing the problem, let me first point out that this is a distinct
The N-Queens Problem: This problem states that given a chess board of size N
I encountered a strange problem this week that I can't explain: I switched my
before reading my problem this work in a normal dynamic web project i create
The Problem This is a very simple-to-understand question. I'm having a user submit 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.