Set Jtable/Column Renderer for booleans

自闭症网瘾萝莉.ら 提交于 2019-12-01 06:21:17

Create a custom renderer. Extend the DefaultTableCellRenderer and add your own code to display whatever you want. It could be a custom Icon or if the "checkmark" is a printable character than you can just set the renderer text to the appropriate character.

Read the JTable API and you will find a link to the Swing tutorial on "How to Use Tables" which will give more information about renderers.

If you need more help post your SSCCE showing the problems you are having creating the renderer.

Edit:

The tutorial shows how to add a custom renderer for a given class but it doesn't show how to add a custom renderer for a specific column. You would use:

table.getColumnModel().getColumn(...).setCellRenderer(...);

Example:

table.setDefaultRenderer(Boolean.class, new BooleanRenderer(true));

with BooleanRenderer

public class BooleanRenderer extends JLabel implements TableCellRenderer
{
.....
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!