From 02f881c5a70b06e356d8e2968d3bace9b5f121b0 Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Fri, 22 Nov 2024 21:36:55 +0100 Subject: [PATCH] correct bug --- src/main/java/ai/nets/samj/gui/ImageSelection.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/ai/nets/samj/gui/ImageSelection.java b/src/main/java/ai/nets/samj/gui/ImageSelection.java index eac5a49..986c333 100644 --- a/src/main/java/ai/nets/samj/gui/ImageSelection.java +++ b/src/main/java/ai/nets/samj/gui/ImageSelection.java @@ -51,16 +51,13 @@ protected & NativeType> RandomAccessibleInterval ge @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { try { - Object item = this.cmbBox.getSelectedItem(); List openSeqs = consumer.getListOfOpenImages(); ComboBoxItem[] objects = new ComboBoxItem[openSeqs.size()]; for (int i = 0; i < objects.length; i ++) objects[i] = openSeqs.get(i); DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(objects); + if (selected != null && objects.length != 0) + comboBoxModel.setSelectedItem(selected); this.cmbBox.setModel(comboBoxModel); - if (item != null && objects.length != 0) - this.cmbBox.setSelectedIndex( - IntStream.range(0, objects.length).filter(i -> objects[i].getId() == ((ComboBoxItem) item).getId()).findFirst().orElse(0) - ); } catch (Exception ex) { ex.printStackTrace(); } @@ -70,11 +67,11 @@ public void popupMenuWillBecomeVisible(PopupMenuEvent e) { public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { try { ComboBoxItem item = (ComboBoxItem) this.cmbBox.getSelectedItem(); - if (selected == null || selected.getId().equals(item.getId())) { + if (selected == null || item == null || !selected.getId().equals(item.getId())) { listener.modelActionsOnImageChanged(); listener.imageActionsOnImageChanged(); - selected = item; } + selected = item; } catch (Exception ex) { ex.printStackTrace(); }