private void removeSelectedConfiguration() { int oldSelection = myList.getSelectedIndex(); myModel.removeElement(mySelection); int size = myList.getModel().getSize(); int newSelection = oldSelection < size ? oldSelection : size - 1; if (newSelection >= 0 && newSelection < size) { myList.setSelectedIndex(newSelection); } }
public FlatWelcomeScreen() { super(new BorderLayout()); mySlidingPanel.add("root", this); setBackground(getMainBackground()); if (RecentProjectsManager.getInstance() .getRecentProjectsActions(false, isUseProjectGroups()) .length > 0) { final JComponent recentProjects = createRecentProjects(); add(recentProjects, BorderLayout.WEST); final JList projectsList = UIUtil.findComponentOfType(recentProjects, JList.class); if (projectsList != null) { projectsList .getModel() .addListDataListener( new ListDataListener() { @Override public void intervalAdded(ListDataEvent e) {} @Override public void intervalRemoved(ListDataEvent e) { removeIfNeeded(); } private void removeIfNeeded() { if (RecentProjectsManager.getInstance() .getRecentProjectsActions(false, isUseProjectGroups()) .length == 0) { FlatWelcomeScreen.this.remove(recentProjects); FlatWelcomeScreen.this.revalidate(); FlatWelcomeScreen.this.repaint(); } } @Override public void contentsChanged(ListDataEvent e) { removeIfNeeded(); } }); projectsList.addFocusListener( new FocusListener() { @Override public void focusGained(FocusEvent e) { projectsList.repaint(); } @Override public void focusLost(FocusEvent e) { projectsList.repaint(); } }); } } add(createBody(), BorderLayout.CENTER); }
static boolean notFiltered(JList list) { ListModel model1 = list.getModel(); if (!(model1 instanceof FilteringListModel)) return true; final FilteringListModel model = (FilteringListModel) model1; return model.getOriginalModel().getSize() == model.getSize(); }