Changing the text color of a JList
Hi,
Is it possible to set the color of only one line in a JList?
I have this small program and i want the text added to the JList to be changing between the color red and the color blue.
publicclass changeColorextends JFrame{
private JScrollPane jScroll;
private JList jList1;
private DefaultListModel listModel;
private JTextField jTextField1;
publicchangeColor(){
super();
initComponents();
}
privatevoid initComponents(){
listModel =new DefaultListModel();
jList1 =new JList(listModel);
jScroll =new JScrollPane (jList1);
jScroll.setMaximumSize(new Dimension(620,400));
jTextField1 =new JTextField();
jTextField1.setMaximumSize(new Dimension(620,20));
jTextField1.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent arg0){
listModel.addElement(jTextField1.getText());
jTextField1.setText(null);
}
});
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
cp.add(jScroll);
cp.add( jTextField1);
setSize(1000,1000);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
}
publicstaticvoid main(String[] args){
JFrame frame =new changeColor ();
}
}
i can change the color of the complete JList but that is not what i want.
Can anyone help me with this please
Greetz
R. Merckx

