From: Jérôme Benoit Date: Fri, 11 Jan 2019 15:33:34 +0000 (+0100) Subject: Go back to JList on the EyeView, JComboBox will be used somewhere else. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3d9fdaf4ca1feb8d0e788f2f0c948d87439e2414;p=Persons_Comparator.git Go back to JList on the EyeView, JComboBox will be used somewhere else. Signed-off-by: Jérôme Benoit --- 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);