JComboBox下拉框怎么显示图片选项?
[code=java][/codeprivate class ComboBoxRenderer extends JLabel implements ListCellRenderer {
@Override
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
// check if this cell represents the current DnD drop location
JList.DropLocation dropLocation = myList.getDropLocation();
if (dropLocation != null
&& !dropLocation.isInsert()
&& dropLocation.getIndex() == index) {
// check if this cell is selected
} else if (isSelected) {
} else {
};
return this;
}
我想做个下拉选择框,里面的选项是图片的形式该怎么写?写个Icon[] 对象数组存图片,怎么样才会显示在下拉框里面?上面的代码要怎么写? java
[解决办法]
http://www.java2s.com/Tutorial/Java/0240__Swing/Comboboxcellrenderer.htm
[解决办法]
实现ListCellBenderer接口来绘制列表单元
http://www.blogjava.net/zeyuphoenix/archive/2010/04/12/318014.html
[解决办法]
JCombobox默认下拉显示和显示项是文本,为了显示其它内容比如图片或者更复杂的东西,则需要设置新的Renderer,JCombobox的Renderer需要实现ListCellRenderer接口.