Swing
public VoyageView() {
String[] locations = new String[]{"Bayonne", "Berlin", "Bern", "Bilbao", "Birmingham", "Bremen", "Brussels"};
JList<String> departingCity = new JList<<String>();
departingCity.setListData(locations);
JList<String> arrivingCity = new JList<<String>();
arrivingCity.setListData(locations);
this.setLayout(new BorderLayout());
JButton searchButton = new JButton("Search");
JButton cancelButton = new JButton("Cancel");
JPanel citySelection = new JPanel(new GridLayout(0,2));
citySelection.add(departingCity);
citySelection.add(arrivingCity);
JPanel buttonBar = new JPanel();
buttonBar.setLayout(new BoxLayout(buttonBar, BoxLayout.Y_AXIS));
buttonBar.add(searchButton);
buttonBar.add(cancelButton);
this.add(buttonBar, BorderLayout.WEST);
this.add(citySelection, BorderLayout.CENTER);
departingCity.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (arrivingCity.getSelectedValue() == null) return;
if (arrivingCity.getSelectedValue().equals(departingCity.getSelectedValue())) {
arrivingCity.clearSelection();
}
}
});
}
Vaadin
public VoyageView() {
String[] locations = new String[]{"Bayonne", "Berlin", "Bern", "Bilbao", "Birmingham", "Bremen", "Brussels"};
ListBox<String> departingCity = new ListBox<String>();
departingCity.setItems(locations);
ListBox<String> arrivingCity = new ListBox<String>();
arrivingCity.setItems(locations);
this.setLayout(new BorderLayout());
FButton searchButton = new FButton("Search");
FButton cancelButton = new FButton("Cancel");
Panel citySelection = new Panel(new GridLayout(0,2));
citySelection.add(departingCity);
citySelection.add(arrivingCity);
Panel buttonBar = new Panel();
buttonBar.setLayout(new BoxLayout(buttonBar, BoxLayout.VERTICAL));
buttonBar.add(searchButton);
buttonBar.add(cancelButton);
this.add(buttonBar, BorderLayout.WEST);
this.add(citySelection, BorderLayout.CENTER);
departingCity.addValueChangeListener(new HasValue.ValueChangeListener<HasValue.ValueChangeEvent<String>() {
@Override
public void valueChanged(HasValue.ValueChangeEvent<String> e) {
if (arrivingCity.getValue() == null) return;
if (arrivingCity.getValue().equals(departingCity.getValue())) {
arrivingCity.setValue(null);
}
}
});
}