且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在JComboBox中加载Tree?

更新时间:2023-01-31 22:35:58

没有默认方法将树放入组合框.有两种选择:

如果可以允许节点扩展,则可以通过在标准JComobBox中的某些选项之前添加空间来达到类似的效果.甚至在叶子选项前还有空格和破折号.

如果需要扩展节点,那么更好的选择是添加一个弹出窗口,该弹出窗口将显示在按钮下方,该按钮用于侦听树中的项目选择.根据GUI的布局,类似这样的选择可能是更好的选择.

How can I show a tree inside a JComboBox popup?

Here is example tree:

Theoretical computer science 
           Mathematical logic 
            Automata theory 
Algorithms and data structures
           Analysis of algorithms
           Algorithms

There is no default way to put a tree in a combo box. There are a couple of options:

If you can give allowing expansion of nodes, you can achieve a similar effect by adding space before some of the options in a standard JComobBox. Or even space and a dash in front of leaf options.

If you need expansion of nodes, then a better option would be to add a popup that appears below a button that listens for selections of items in the tree. Something like this might be a better choice depending on how your GUI is laid out.