JComponent () { myPackageTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { List<PackageSet> selection = getSelectedSets(false); myInclude.setSelection(selection); myExclude.setSelection(selection); List<PackageSet> recursive = getSelectedSets(true); myIncludeRec.setSelection(recursive); myExcludeRec.setSelection(recursive); } }); JPanel buttonsPanel = new JPanel(new VerticalLayout(5)); buttonsPanel.add(new JButton(myInclude)); buttonsPanel.add(new JButton(myIncludeRec)); buttonsPanel.add(new JButton(myExclude)); buttonsPanel.add(new JButton(myExcludeRec)); return buttonsPanel; }