From 3d9fdaf4ca1feb8d0e788f2f0c948d87439e2414 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 11 Jan 2019 16:33:34 +0100 Subject: [PATCH] Go back to JList on the EyeView, JComboBox will be used somewhere else. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/EyeView.java | 9 ++++++--- src/Main.java | 3 +-- src/MainWindowsView.java | 9 ++------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/EyeView.java b/src/EyeView.java index a80a31a..8e75698 100644 --- a/src/EyeView.java +++ b/src/EyeView.java @@ -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); } diff --git a/src/Main.java b/src/Main.java index 361c00e..5bac73e 100644 --- a/src/Main.java +++ b/src/Main.java @@ -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); diff --git a/src/MainWindowsView.java b/src/MainWindowsView.java index c3688ba..0b89d5d 100644 --- a/src/MainWindowsView.java +++ b/src/MainWindowsView.java @@ -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 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); -- 2.34.1