是否可以在JList内的一个JLabel上使用不同的字体颜色? [英] Is it possible to have a different font colors on one JLabel inside in the JList?

查看:188
本文介绍了是否可以在JList内的一个JLabel上使用不同的字体颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Jlist中有一个单词列表,旁边的每个单词都是他们的定义。我希望单词的字体具有与其定义不同的颜色。我的问题是,是否有可能在一个Jlist中有两种不同的颜色?

I have a list of words in my Jlist and beside of every words are their definitions. I want that the font of the words are having a different colors than their definition. My question is that, Is it possible to have a two different colors in one Jlist?

我是否必须使用ListCellRenderer?

Do I have to use ListCellRenderer?

谢谢......

推荐答案

我想你可以使用< html>样式。它可能看起来很奇怪但是如果你通过< html>(不是大写字母HTML)开始你的文本(字符串值),你将能够使用html代码在你的标签上。

I think you may use "<html>" style. It might look some odd but if you start your text (String value) by "<html>" (not capital letter HTML), you will be able to use html codes on your labels.

作为例子;

new JLabel("<html><font color=red>RED</font> - <font color=navy>Navy</font></html>");

类似于JList。

这篇关于是否可以在JList内的一个JLabel上使用不同的字体颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆