我有一个JComboBox
用作编辑器JTable
。在图片中,您可以在标记的列中看到它们Produs
。我想使用独立的设计JComboBox
在网格单元中,特别是组合框的右侧部分,其中网格单元中缺少三角形,因此用户无需单击其中之一即可知道网格单元是组合框。我如何应用该设计JComboBox
(IsBackFlush
)到JComboBoxes
在网格中?
本质上,我该如何设计comboBox2
基于的设计comboBox1
?谢谢。
Working from this complete example https://stackoverflow.com/a/7356518/230513 as a common frame of reference, note how the appearance of unselected cells in the ITEM_COL
column is due to the default renderer http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editrender. The arrow button typical of a stand-alone JComboBox
only appears when the cell's editor is evoked, as by clicking on the cell or pressing Space when the cell is selected. You can add a triangle in a custom renderer:
final JComboBox combo = new JComboBox(items);
TableColumn col = table.getColumnModel().getColumn(ITEM_COL);
col.setCellRenderer(new DefaultTableCellRenderer(){
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
JLabel label = (JLabel) super.getTableCellRendererComponent(table,
value, isSelected, hasFocus, row, column);
label.setIcon(UIManager.getIcon("Table.descendingSortIcon"));
return label;
}
});
附录:@aterai 提供了一个更完整的示例here https://stackoverflow.com/a/12844115/230513.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)