Search code examples
javaswingjtabletablecellrenderertablemodel

JTable how to render different swing objects in the same column


I want to render different swing components in the same JTable column. For example, I want to have few different comboboxes, jlabels and jcheckboxes in the same column. http://docs.oracle.com/javase/tutorial/uiswing/components/table.html provides information how to render only one type of combobox per column, however it is not enough.

How can I setup table cell renderer so that it would achieve this functionality?


Solution

  • If you need to use different editors/renderers in the same column, you can follow the approach described in this answer and override JTable#getCellEditor() based on the cell (column and row intersection). JTable#getCellRenderer() can be overriden if needed as well.

    In Concepts: Editors and Renderers is described the strategy followed by tables to get a renderer/editor so you can take advantage of it to solve your problem.