您的位置:首页 > 其它

[jtable]设置复选框前景色与背景色

2013-06-27 10:13 309 查看




//表JComboBox数据

String[]status={"启用","禁用","停用"};
JComboBoxcom=newJComboBox(status);
JComboBoxRendererselect=newJComboBoxRenderer();
com.setRenderer(select);
//ListCellRenderer监听

classJComboBoxRendererextendsJLabelimplementsListCellRenderer{
publicJComboBoxRenderer(){
setOpaque(true);
}
publicComponentgetListCellRendererComponent(JListlist,
Objectvalue,
intindex,
booleanisSelected,
booleancellHasFocus){
setText(value.toString());
Colorbackground;
Colorforeground;
//checkifthiscellrepresentsthecurrentDnDdroplocation
JList.DropLocationdropLocation=list.getDropLocation();
if(dropLocation!=null
&&!dropLocation.isInsert()
&&dropLocation.getIndex()==index){

background=Color.BLUE;
foreground=Color.WHITE;
//checkifthiscellisselected
}elseif(isSelected){
background=Color.RED;
foreground=Color.WHITE;
//unselected,andnottheDnDdroplocation
}else{
background=Color.yellow;
foreground=Color.BLACK;
};
setBackground(background);
setForeground(foreground);

returnthis;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: