如何使JComboBox表编辑器具有普通JComboBox的设计?

Laj*_*pad 2 java swing jtable tablecelleditor jcombobox

我有一个JComboBox用作编辑器的人JTable.在图片中,您可以在标有列的列中看到它们Produs.我想JComboBox在网格单元格中使用独立设计,特别是组合框的右侧部分,网格单元格中缺少三角形,因此用户将知道网格单元格是组合框而不必点击其中一个.如何将JComboBox(IsBackFlush)的设计应用于JComboBoxes网格中?

从本质上讲,我如何comboBox2根据设计进行设计comboBox1?谢谢.

裁剪图像

tra*_*god 5

使用此完整示例作为公共参考框架,请注意ITEM_COL列中未选定单元格的外观是如何由默认渲染器引起的.独立的箭头按钮JComboBox仅在引发单元格编辑器时出现,例如单击单元格或按下Space单元格时按下.您可以在自定义渲染器中添加三角形:

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;
    }
});
Run Code Online (Sandbox Code Playgroud)

附录:在这里可以看到由@aterai提供的更完整的例子.