How to change background color of the selected item in JList dynamically?

Something like the following should help as a starting point: public class SelectedListCellRenderer extends DefaultListCellRenderer { Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component c = super. GetListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (isSelected) { c. SetBackground(Color.

RED); } return c; } } // During the JList initialisation... jlist1. SetCellRenderer(new SelectedListCellRenderer()).

If I am cleary understand your - look into javax.swing. ListCellRenderer. You need or reimplement it or extend javax.swing.

DefaultListCellRenderer and customize getListCellRendererComponent method.

Java - Changing JList row color at runtime - Stack Overflow.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions