Color « JList « Java Swing Q&A





1. How to generate a Jlist with alternating colors    stackoverflow.com

In Java how do I get a JList with alternating colors? Any sample code?

2. How to change background color of the selected item in JList dynamically    stackoverflow.com

How can I change the background color of the item which is selected in JList dynamically?

3. In Swing, is there a property to set a JList disabled foreground color?    stackoverflow.com

In Swing, is there a property to set a JList disabled foreground color? I'm using the Netbeans GUI builder and I want to add a property to the resource properties file that ...

5. 2 colours for items in JLIST    coderanch.com

6. Changing the text colour of JList items    coderanch.com

You'll need to make a new ListCellRenderer and do something like the following... import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class TestList extends JFrame { public TestList() { super( "Test List" ); String[] data = { "Frodo", "Sam", "Merry", "Pippin", "Gandalf", "Legolas", "Gimli", "Aragorn", "Boromir" }; JList list = new JList( data ); list.setCellRenderer( new MyListRenderer() ); JPanel p ...

7. Maintain the Foreground text color in JList[urgent]    coderanch.com

It "grays out" the label to show the user that it cannot be selected... normally, this is really something you would really want to do... But if you don't you'll have to override the default ListCellRenderer... import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; public class NoDisabled extends JFrame { JList list; public static void main( String[] arg ) { new ...

8. Multi-Colored JList    coderanch.com

9. JList - items in different color    coderanch.com





10. Changing the background color on JList's    coderanch.com

You would just create a new ListCellRenderer for the list that set the color of the background of the cell based on the index. Take a look at the WhiteYellowCellRenderer inner class in the following code : import java.awt.Color; import java.awt.Component; import javax.swing.DefaultListCellRenderer; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JPanel; public class WhiteYellow { private JFrame frame; private JList list; public WhiteYellow() ...

11. In disabled mode, how do i make JList data to be in black color    coderanch.com

Hi, I added Cell renderer but even then it is not working. class PackagesCellRenderer extends net.java.plaf.windows.xp.DefaultListCellRenderer implements ListCellRenderer { public Component getListCellRendererComponent( JList list, Object value, // value to display int index, // cell index boolean isSelected, // is the cell selected boolean cellHasFocus) // the list and the cell have the focus { if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else ...