I ve got a problem I can t get rid of.
就如你所知,我对使用便携式导弹说得很新,因此答案可能简单,但我无法找到解决办法。
因此,I ve got a JTable using an 摘要TableModel, which overes the
public Class<?> getColumnClass(int columnIndex_p)
说明每个栏目的类型的方法。 其中一人为蓝.。
当我使用简便可调时
table_l = new JTable(new MyTableModel());
一切都属于罚款,而使用检查箱(在/起飞)正确展示诱骗的价值观。
现在,我想把案文放在每个囚室上(以及以后可能有更多的选择)。
So I define a new DefaultTableCellRenderer for each column, like this :
DefaultTableCellRenderer cellRenderer_l = new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
// delegate the rendering part to the default renderer (am i right ???)
Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
return comp;
}
}
and then I just set the horizontal alignment of this CellRender with :
cellRenderer_l.setHorizontalAlignment(JLabel.CENTER);
然后,我把这个新单元安装在表一栏:
for (int i = 0; i < table_l.getColumnCount(); ++i) {
table_l.getColumnModel().getColumn(i).setCellRenderer(cellRenderer_l);
}
But, with the new CellRenderer, the displayed JTable isn t using the getColumnClass() method of my TableModel anymore, and thus just display "true/false" String on Boolean values.
我不知道如何让它像以前那样继续使用“ColumnClass”。
If someone has the answer... Thank you
EDIT: thanks for all the clarifications you made. In fact, my real question was : "how to affect all DefaultRenderer of a JTable to make them center their result in the JTable s cells"