在ListCellRenderer中对文字用html标签对文字进行换行以后,发现选中部分的文字颜色变成了黑色,而不是正常的白色.没有选中的部分就是正常的.如果不使用换行标记<br>也是正常的.这是什么问题?是什么原因造成的呢?
这是我自定义的ListCellRenderer的代码.
JList也是自定义的,value保证是String[] public Component getListCellRendererComponent(JList list, Object value,int index,boolean isSelected,boolean cellHasFocus)
{
setComponentOrientation(list.getComponentOrientation());
if (isSelected) {
setBackground(JEditList.selectBackColor);
setForeground(JEditList.selectForceColor);
}
else {
setBackground(JEditList.unSelBackColor);
setForeground(JEditList.unSelForceColor);
}
setEnabled(list.isEnabled());
setFont(list.getFont()); Border border = null;
if (cellHasFocus) {
if (isSelected)
border = UIManager.getBorder("List.focusSelectedCellHighlightBorder");
if (border == null)
border = UIManager.getBorder("List.focusCellHighlightBorder");
} else
border = new EmptyBorder(1, 1, 1, 1) ;
setBorder(border); String[] listData = (String[])value;
text = "<html>" + listData[2] + "<br>" + listData[3] + "</html>";//就这里,这样使用的话,选中List中此Item的话,两行文字都是用黑色字体显示(正常的是白色.如果不加<br>就是白色)
setText(text) ; return this ;
}
这是我自定义的ListCellRenderer的代码.
JList也是自定义的,value保证是String[] public Component getListCellRendererComponent(JList list, Object value,int index,boolean isSelected,boolean cellHasFocus)
{
setComponentOrientation(list.getComponentOrientation());
if (isSelected) {
setBackground(JEditList.selectBackColor);
setForeground(JEditList.selectForceColor);
}
else {
setBackground(JEditList.unSelBackColor);
setForeground(JEditList.unSelForceColor);
}
setEnabled(list.isEnabled());
setFont(list.getFont()); Border border = null;
if (cellHasFocus) {
if (isSelected)
border = UIManager.getBorder("List.focusSelectedCellHighlightBorder");
if (border == null)
border = UIManager.getBorder("List.focusCellHighlightBorder");
} else
border = new EmptyBorder(1, 1, 1, 1) ;
setBorder(border); String[] listData = (String[])value;
text = "<html>" + listData[2] + "<br>" + listData[3] + "</html>";//就这里,这样使用的话,选中List中此Item的话,两行文字都是用黑色字体显示(正常的是白色.如果不加<br>就是白色)
setText(text) ; return this ;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货