3 import java
.util
.Arrays
;
5 public class EyeView
extends JPanel
{
8 private JList colorsList
;
15 this.label
= new JLabel();
16 this.label
.setText("Eyes color");
17 this.colorsList
= new JList
<>(this.getEyeObj().getColorsList());
18 this.colorsList
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
19 this.colorsList
.setLayoutOrientation(JList
.VERTICAL
);
20 this.colorsList
.setSelectedIndex(Arrays
.asList(this.getEyeObj().getColorsList()).indexOf(this.getEyeObj().getStrColor()));
21 this.colorsList
.setCellRenderer(new EyeCellRenderer());
29 public Eye
getEyeObj() {
36 public void setEyeObj(Eye eyeObj
) {
40 public JList
getColorsList() {
44 private static class EyeCellRenderer
extends DefaultListCellRenderer
{
45 public Component
getListCellRendererComponent(JList list
, Object value
, int index
, boolean isSelected
, boolean cellHasFocus
) {
46 Component c
= super.getListCellRendererComponent(list
, value
, index
, isSelected
, cellHasFocus
);
47 Eye currentEye
= new Eye((String
) list
.getModel().getElementAt(index
));
48 c
.setBackground(currentEye
.getColor());
49 c
.setForeground(Color
.WHITE
);
51 setBackground(getBackground().darker());