Search code examples
javaswingfontsjlistbold

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


Solution

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