如何使JComboBox表编辑器具有普通JComboBox的设计? [英] How to make a JComboBox table editor have the design of an ordinary JComboBox?
问题描述
我有一个 JComboBox
用作 JTable
中的编辑器。在图片中,您可以在标有 Produs
的列中看到它们。我想在网格单元格中使用独立的 JComboBox
的设计,特别是组合框的右侧部分,网格单元格中缺少三角形,所以用户将知道网格单元格是组合框而无需单击其中一个。如何将 JComboBox
( IsBackFlush
)的设计应用于 JComboBoxes $网格中的c $ c>?
I have a JComboBox
used as an editor in a JTable
. In the picture you can see them in the column labeled Produs
. I would like to use the design of the stand-alone JComboBox
in the grid cells, particularly the right part of the combo box where the triangle is missing from the grid cells, so a user will know that the grid cells are combo boxes without having to click on one of them. How can I apply the design of the JComboBox
(IsBackFlush
) to the JComboBoxes
in the grid?
基本上,如何根据<$的设计设计 comboBox2
C $ C> comboBox1 ?谢谢。
Essentially, how can I design comboBox2
based on the design of comboBox1
? Thanks.
推荐答案
使用完整的示例一个共同的参考框架,请注意 ITEM_COL
列中未选定单元格的出现是由于 默认渲染器 。独立 JComboBox
的典型箭头按钮仅在引发单元格编辑器时出现,例如单击单元格或按 Space 时细胞被选中。您可以在自定义渲染器中添加三角形:
Working from this complete example as a common frame of reference, note how the appearance of unselected cells in the ITEM_COL
column is due to the default renderer. 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而出现更完整的示例其他。
Addendum: A more complete example due to @aterai is seen here.
这篇关于如何使JComboBox表编辑器具有普通JComboBox的设计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!