A part of Text should be bold in jList
can i set a part of the text in a jList bold?
in some component i开发者_开发知识库 can set the text with html-marks to bold but not here.. is there any other way to do this?..
The default font is bold for a JList (in the Metal LAF). So you would first need to change the default font and then add your HTML string to the ListModel to only bold the text that you want displayed bold. Something like:
String[] items = { "one", "<html>normal <b>bold</b> normal</html>" };
JList list = new JList( items );
list.setFont( list.getFont().deriveFont(Font.PLAIN) );
If you have problems then post your SSCCE demonstrating the problem.
You should be able to tie into the ListCellRenderer
. Since the DefaultListCellRenderer
extends JLabel
, I'd expect there to be some way to wedge in HTML that's getting passed over in the default usage.
Have you tried creating a custom list cell renderer yet? If not, you may wish to give this a try. The tutorials will show you how. Please have a look here:
http://download.oracle.com/javase/tutorial/uiswing/components/list.html
http://download.oracle.com/javase/tutorial/uiswing/components/list.html#renderer
http://download.oracle.com/javase/tutorial/uiswing/components/combobox.html#renderer
精彩评论