This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JList SelectionForeground problem when BOLD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JList SelectionForeground problem when BOLD " Watch "JList SelectionForeground problem when BOLD " New topic

JList SelectionForeground problem when BOLD

Pinto K

Joined: Nov 11, 2003
Posts: 2
In my JList, there are items which are bold and not bold.

When the list contain a single bold item and at the selection time (by mouse) , the Foreground Color and BackGround Color are blue (can't read the item in the list).
The setSelectionForeground method will not get effect in selected stage.

This issue will get when we comment the line as
// listModel.addElement("Am Not Bold");
on the below java pgm.

Why this happens ? How can I add a bold item in JList without this issue ?
Any other solutions for this ?

please help
thanks in advance.

-----------------------------Java Program-----------------------

import javax.swing.*;
import java.awt.*;

public class ListExample extends JFrame
private JList list = new JList();
private DefaultListModel listModel = new DefaultListModel();
listModel.addElement("<html><B>Am Bold</B></html>");
listModel.addElement("Am Not Bold");
public static void main(String s[])
UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
}catch(Exception e){}
ListExample l = new ListExample();
Suman Mummaneni
Ranch Hand

Joined: Dec 14, 2004
Posts: 87

I have tried out your code it works fine. When the bold text is selected in the List box the foregound color is white and background color is blue. and the text is visible in bold.

Suman Mummaneni
It is sorta covered in the JavaRanch Style Guide.
subject: JList SelectionForeground problem when BOLD
Similar Threads
right click with Jlist
How to disable a particular Jliste element?
drag and drop DND click, then move??
need help on JList
How to move the selected row in Jtable to be the first row in the table