如何在Java中为JComboBox添加分隔符?
我有一个 JComboBox ,并希望在元素列表中有一个分隔符。我如何用Java做到这一点?
I have a JComboBox and would like to have a separator in the list of elements. How do I do this in Java?
一个示例场景,它可以派上用场进行字体系列选择;类似于Word和Excel中的font-family-selection-control。在这种情况下,我想在顶部显示最常用的字体,然后是分隔符,最后按字母顺序显示分隔符下面的所有字体系列。
A sample scenario where this would come in handy is when making a combobox for font-family-selection; similar to the font-family-selection-control in Word and Excel. In this case I would like to show the most-used-fonts at the top, then a separator and finally all font-families below the separator in alphabetical order.
可以有人帮我怎么做或者这在Java中不可能吗?
Can anyone help me with how to do this or is this not possible in Java?
有一个非常简短的教程,有一个例子它展示了如何在java2s上使用自定义ListCellRenderer
http:/ /www.java2s.com/Code/Java/Swing-Components/BlockComboBoxExample.htm
There is a pretty short tutorial with an example that shows how to use a custom ListCellRenderer on java2s http://www.java2s.com/Code/Java/Swing-Components/BlockComboBoxExample.htm
基本上它涉及在列表模型中插入已知占位符以及何时你在ListCellRenderer中检测到占位符,你返回一个'new JSeparator(JSeparator.HORIZONTAL)'的实例
Basically it involves inserting a known placeholder in your list model and when you detect the placeholder in the ListCellRenderer you return an instance of 'new JSeparator(JSeparator.HORIZONTAL)'