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?..

Upvotes: 2

Views: 3645

Answers (3)

camickr
camickr

Reputation: 324118

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.

Upvotes: 4

Michael Brewer-Davis
Michael Brewer-Davis

Reputation: 14276

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.

Upvotes: 4

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285403

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

Upvotes: 2

Related Questions