public void selectPrevious() { if (selectionModel.getSelectedIndex() == 0) { selectionModel.selectLast(); } else { selectionModel.selectPrevious(); } }
public void start(Stage stage) { stage.setTitle("ListView demo"); FlowPane rootNode = new FlowPane(10, 10); rootNode.setAlignment(Pos.CENTER); Scene scene = new Scene(rootNode, 200, 120); stage.setScene(scene); responseLabel = new Label("Select Transport Type"); ObservableList<String> transportTypes = FXCollections.observableArrayList("Train", "Car", "Airplane"); ListView<String> transportListView = new ListView(transportTypes); transportListView.setPrefSize(80, 80); MultipleSelectionModel<String> listViewSelectionModel = transportListView.getSelectionModel(); listViewSelectionModel .selectedItemProperty() .addListener( new ChangeListener<String>() { public void changed( ObservableValue<? extends String> changed, String oldValue, String newValue) { responseLabel.setText("Transport selected is " + newValue); } }); rootNode.getChildren().addAll(transportListView, responseLabel); stage.show(); }
public void selectNext() { if (selectionModel.getSelectedIndex() == tabList.getItems().size() - 1) { selectionModel.selectFirst(); } else { selectionModel.selectNext(); } }
public TabPane(ApplicationPane appPane) { this.appPane = appPane; getStylesheets().add(Mercury.class.getResource("/res/css/TabPane.css").toExternalForm()); setMinWidth(200); setMaxWidth(200); final TabButtonPane buttonPane = new TabButtonPane(); final VBox tabListBox = new VBox(); tabListBox.getStyleClass().add("dark-pane"); tabListBox.setId("tab-list"); setVgrow(tabListBox, Priority.ALWAYS); tabList = new ListView<>(); setVgrow(tabList, Priority.ALWAYS); selectionModel = tabList.getSelectionModel(); selectionModel .selectedIndexProperty() .addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observableValue, Number number, Number number2) { if (number2 == 0) { tabList.getStyleClass().add("first"); } else { tabList.getStyleClass().remove("first"); } } }); selectionModel.selectedItemProperty().addListener(new TabClickedListener()); tabList.setCellFactory( new Callback<ListView<Tab>, ListCell<Tab>>() { public ListCell<Tab> call(ListView<Tab> tabListView) { return new TabCell(); } }); tabListBox.getChildren().add(tabList); getChildren().addAll(buttonPane, tabListBox); }
public void close(Tab tab, boolean action) { if (getSelected().equals(tab)) { if (selectionModel.getSelectedIndex() == tabList.getItems().size()) { selectPrevious(); } else { selectNext(); } } { Iterator<Tab> it = tabList.getItems().iterator(); while (it.hasNext()) { Tab _tab = it.next(); if (_tab.equals(tab)) { it.remove(); if (action) { if (tab.getEntity() instanceof Channel) { appPane.getContentPane().getConnection().part((Channel) tab.getEntity()); } else if (tab.getEntity() instanceof Server) { appPane.getContentPane().getConnection().quit(""); } } break; } } } if (tab.getEntity() instanceof Server) { Iterator<Tab> it = tabList.getItems().iterator(); while (it.hasNext()) { Tab _tab = it.next(); if (_tab.getConnection().equals(tab.getConnection())) { close(_tab); } } } Mercury.saveConnections(); }
public void select(Tab tab) { selectionModel.select(tab); }
public Tab getSelected() { return selectionModel.getSelectedItem(); }