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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:22:15+00:00 2026-06-10T00:22:15+00:00

I basically have a JTree where I show certain information. In one of the

  • 0

I basically have a JTree where I show certain information. In one of the “sub-trees” I got a panel which consists of a panel with GridLayout(0,2) and a JPanel as well as a combobox.

I’ve noticed that no components in my tree react on input. This of course means that my combobox won’t react when I try to click on it. I tried to implement a default cell editor, which worked but not like I wanted to. It basically opened the menu but when I selected one of the items it replaced the JLabel so only the combobox was visible.

Pictures

Before clicking on the box enter image description here

After clicking on the box enter image description here

Code that I tried with

 TreeCellEditor editor = new DefaultCellEditor(blockedAlternatives);
                infoTree.setEditable(true);
                infoTree.setCellEditor(editor);

I obviously don’t want to be able to edit the whole tree, I just want to be able to show the combobox’s menu. I just took this code from the web for testing.
Any ideas?

  • 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-10T00:22:17+00:00Added an answer on June 10, 2026 at 12:22 am

    It basically opened the menu but when I selected one of the items it
    replaced the JLabel so only the combobox was visible.

    Well that is what you’d excpect as thats how the DefaultCellEditor(JComboBox jcb) is meant to be:

        import java.awt.BorderLayout;
        import java.util.Properties;
        import javax.swing.*;
        import javax.swing.tree.TreeCellEditor;
    
        public class TreeEditJComboBox {
    
            public static void main(String args[]) {
                JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                Properties props = System.getProperties();
                JTree tree = new JTree(props);
    
    
                JComboBox comboBox = new JComboBox(new String[]{"A", "B", "C"});
                TreeCellEditor editor = new DefaultCellEditor(comboBox);
    
                tree.setEditable(true);
                tree.setCellEditor(editor);
    
                JScrollPane scrollPane = new JScrollPane(tree);
                frame.add(scrollPane, BorderLayout.CENTER);
                frame.setSize(300, 150);
                frame.setVisible(true);
            }
    
        }
    }
    

    You could try making your own DefaultCellEditor and override getTableCellEditorComponent() and then return a JPanel which holds the JLabel and JComboBox, something like:

    class MyDefaultCellEditor extends DefaultCellEditor {
    
    public MyDefaultCellEditor(JComboBox comboBox) {
        super(comboBox);
    }
    
    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
       //return custom coponent
        return super.getTableCellEditorComponent(table, value, isSelected, row, column);
    }
    }
    

    then:

     TreeCellEditor editor = new MyDefaultCellEditor(blockedAlternatives);
    

    you may have to override a few other methods too. I was just showing the logic

    References:

    • Creating a DefaultCellEditor: JComboBox

    • extends DefaultCellEditor

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

Sidebar

Related Questions

I basically have a Money value type, which consists of Amount and Currency .
I basically have a program that filters records from one excel file to another
I basically have the following class: .sf-sub-indicator { background: url(/abcprod/images/arrows-ffffff.png) no-repeat -10px -100px; }
I basically have a splitview controller and immediately I would like to show a
I basically have one column that needs to be substringed. The format of the
Since I basically have a model per view. I arrange my models in sub
So i basically have a Stack Panel, And i'm using a foreach loop to
I have documents which I am indexing with Lucene. These documents basically have a
I basically have two child classes which have the same parent class. what I
i have a page which is basically just a big unordered list - sort

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.