在java的list框的字体颜色怎么改变?
1个回答
展开全部
list.setCellRenderer(new DefaultListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if(value.toString().indexOf("*") != -1)
comp.setForeground(Color.RED);
else
comp.setForeground(Color.BLACK);
return comp;
}
});
这样做完后jlist没有滚动条
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if(value.toString().indexOf("*") != -1)
comp.setForeground(Color.RED);
else
comp.setForeground(Color.BLACK);
return comp;
}
});
这样做完后jlist没有滚动条
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询