JTable单元格设置问题! 1.一个JTable,要让第一列的背景色为黑色,其他列背景色不变。什么方法可以解决?2.JTable可编辑,当输入数字的时候,右对齐,输入汉字和字母的时候,左对齐,什么方法可以解决? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1、可以设置Table的CellRenderer实现,在Renderer的实现方法中,对column == 0进行判断,if(column == 1){setBackground(Color.black);}2、重写TableModel的 getColumnClass方法,只能对一列进行设置。也可以通过Renderer实现,实际上默认的Renderer也就是一个Label,对Renderer的value进行判断;if(isNumber){setsetHorizontalAlignment(LEFT or RIGHT);} table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (column == 0) { this.setBackground(Color.BLACK); } try { Integer.parseInt(value.toString()); setHorizontalAlignment(RIGHT); } catch (NumberFormatException e) { setHorizontalAlignment(LEFT); } return this; } }); 二楼的不对,我在一楼给你提供了一个思路,你最好还是写一个isNumber的方法,对数值进行判断。具体可以使用正则来实现 求解求解 SWT中打开对话框或者新窗口,如何将原窗口锁定? 算是循环、类和文件处理的问题吧 有个疑问,请大家帮忙解答 一个验证帐号和密码的问题 在线等 请java高手帮忙,万分感谢!!着急等待中,跪谢!! 非Apache高手莫入!奇怪+恐怖! 不会吧!路人甲等高手何在?这个问题都搞不定,还能做UI编程吗? Has any one been using JDO? 一个程序如何连接任何一个大型数据库呢? 一个超级变态的问题!!!解答下。。。 JTable到文件
if(column == 1){
setBackground(Color.black);
}2、重写TableModel的 getColumnClass方法,只能对一列进行设置。也可以通过Renderer实现,实际上默认的Renderer也就是一个Label,对Renderer的value进行判断;if(isNumber){
setsetHorizontalAlignment(LEFT or RIGHT);
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (column == 0) {
this.setBackground(Color.BLACK);
}
try {
Integer.parseInt(value.toString());
setHorizontalAlignment(RIGHT);
} catch (NumberFormatException e) {
setHorizontalAlignment(LEFT);
}
return this;
}
});