Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JList SelectionForeground problem when BOLD

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
--list.setSelectionForeground(Color.white);--

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();
ListExample()
{
setSize(300,300);
getContentPane().setLayout(null);
list.setBounds(50,30,200,200);
list.setSelectionForeground(Color.white);
list.setModel(listModel);
getContentPane().add(list);
listModel.addElement("<html><B>Am Bold</B></html>");
listModel.addElement("Am Not Bold");
}
public static void main(String s[])
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
}catch(Exception e){}
ListExample l = new ListExample();
l.setVisible(true);
}
}
 
Ranch Hand
Posts: 99
Android Mac Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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.
 
    Bookmark Topic Watch Topic
  • New Topic