如何自定义JComboBox,以使弹出窗口为JTree(而不是列表)? [英] How do I customize a JComboBox so that the pop-up is a JTree (instead of a list)?

查看:88
本文介绍了如何自定义JComboBox,以使弹出窗口为JTree(而不是列表)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个组合框,以便可以在弹出窗口中放置我喜欢的任何控件,在我的特定情况下为JTree.看一下JComboBox的实现方式,该弹出窗口实际上是由UI委托创建的.更改的问题在于,对于每种外观,都需要重新实现它,这是我不想做的事情...

I am trying to create a combo box so that I can put whatever control I prefer within the pop-up, in my specific case a JTree. Having a look at how the JComboBox is implement, the pop-up is really created by the UI delegate. The problem in changing that is that it would need to be re-implemented for each look and feel, which is something I do not want to do...

我基本上想要一个组件,它具有JComboBox的外观(在当前外观下),而弹出窗口是JTree(在当前外观上).

I basically want a component that it has the look and feel of a JComboBox (in the current look and feel) and the popup is a JTree (in the current look and feel).

最简单的方法是什么?

推荐答案

JComboBox本身无法执行您想要的操作.如果您绝对喜欢让它像JComboBox一样工作的概念,则可以使JButton在单击时弹出一个JPanel.然后,JPanel可以在其中拥有您想要的任何东西(JTree等).

JComboBox itself can't do what you want. If you're absolutely wedded to the concept of having it act like a JComboBox, you could make a JButton pop up a JPanel on click. Then the JPanel could have whatever you want inside it (JTree, etcetera).

这篇关于如何自定义JComboBox,以使弹出窗口为JTree(而不是列表)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆