Go back to JList on the EyeView, JComboBox will be used somewhere else.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 11 Jan 2019 15:33:34 +0000 (16:33 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 11 Jan 2019 15:33:34 +0000 (16:33 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/EyeView.java
src/Main.java
src/MainWindowsView.java

index a80a31a768ed5d4f21abdfd690b1aa9939a28ebc..8e7569855b31e566dfb38ddf02ddc0e3e9667758 100644 (file)
@@ -1,9 +1,10 @@
 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
@@ -12,8 +13,10 @@ public class EyeView extends JPanel {
         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);
     }
index 361c00e88361eba731b55758b5c697e8faab326c..5bac73ebab3fa905a7284370d082a79ba12e49a1 100644 (file)
@@ -17,8 +17,7 @@ public class Main {
         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);
 
index c3688ba206e60bf9f7ef80b3bf9a145d71e8893e..0b89d5d44868d5e267c28ae68919018251f3f0fe 100644 (file)
@@ -26,15 +26,10 @@ public class MainWindowsView extends JFrame {
         });
         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);