import javax.swing.*;
+import java.util.Arrays;
public class EyeView extends JPanel {
private Eye eyeObj;
private JLabel label;
- private JComboBox colorsList;
+ private JList colorsList;
/**
* @param eyeObj
setEyeObj(eyeObj);
this.label = new JLabel();
this.label.setText("Eyes color");
- this.colorsList = new JComboBox<>(this.getEyeObj().getColorsList());
- this.colorsList.setSelectedItem(this.getEyeObj().getStrColor());
+ this.colorsList = new JList<>(this.getEyeObj().getColorsList());
+ this.colorsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ this.colorsList.setLayoutOrientation(JList.VERTICAL);
+ this.colorsList.setSelectedIndex(Arrays.asList(this.getEyeObj().getColorsList()).indexOf(this.getEyeObj().getStrColor()));
add(label);
add(colorsList);
}
Person person4 = new Person("Sophia", "Brasil", 155, 57, "blue");
personArrayList.add(person4);
- //Person emptyPerson = new Person();
- Person emptyPerson = person2;
+ Person emptyPerson = new Person();
emptyPerson.setPersonArrayList(personArrayList);
PersonView emptyPersonView = new PersonView(emptyPerson);
});
fileMenu.add(exit);
- //Get all Swing/AWT primitive components in the views and add them to the main panel.
+ //Get all Swing/AWT JPanel in the views and add them to the main panel.
ArrayList<Component> components = new ArrayList<>();
for (int i = 0; i < panel.getComponentCount(); i++) {
- if ((panel.getComponent(i) instanceof Container)) {
- Container subContainer = (Container) panel.getComponent(i);
- for (int j = 0; j < subContainer.getComponentCount(); j++) {
- components.add(subContainer.getComponent(j));
- }
- }
+ components.add(panel.getComponent(i));
}
for (Component component : components) {
panel.add(component);