Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ArrayList<String> ServiceToDelete = R.OffrirService();
- List<String> seup = se.stream().filter(elem -> !ServiceToDelete.contains(elem)).collect(Collectors.toList());
- for (int x = 0; x < seup.size(); x++) {
- String g = seup.get(x);
- li_se.getItems().removeIf((t) -> {
- return ((JFXCheckBox) t).getText().equals(g);
- });
- //System.out.println(li_se.getItems().indexOf(ServiceToDelete.get(x)));
- }
- // observe item's on property and display message if it changes:
- item.onProperty().addListener((obs, wasOn, isNowOn) -> {
- System.out.println(item.getName() + " changed on state from " + wasOn + " to " + isNowOn);
- if (isNowOn) {
- listView.getItems().remove(item);
- }
- });
- listView.getItems().removeIf((t) -> {
- return ((Item) t).getName().equals("Item 9");
- });
- import javafx.application.Application;
- import javafx.beans.property.BooleanProperty;
- import javafx.beans.property.SimpleBooleanProperty;
- import javafx.beans.property.SimpleStringProperty;
- import javafx.beans.property.StringProperty;
- import javafx.scene.Scene;
- import javafx.scene.control.ListView;
- import javafx.scene.control.cell.CheckBoxListCell;
- import javafx.scene.layout.BorderPane;
- import javafx.stage.Stage;
- public class ListViewWithCheckBox extends Application
- {
- @Override
- public void start(Stage primaryStage)
- {
- ListView<Item> listView = new ListView<>();
- for (int i = 1; i <= 20; i++) {
- Item item = new Item("Item " + i, false);
- // observe item's on property and display message if it changes:
- item.onProperty().addListener((obs, wasOn, isNowOn) -> {
- System.out.println(item.getName() + " changed on state from " + wasOn + " to " + isNowOn);
- if (isNowOn) {
- listView.getItems().remove(item);
- }
- });
- listView.getItems().add(item);
- }
- listView.setCellFactory(CheckBoxListCell.forListView((Item item) -> item.onProperty()));
- removeItem(listView);
- BorderPane root = new BorderPane(listView);
- Scene scene = new Scene(root, 250, 400);
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- public static class Item
- {
- private final StringProperty name = new SimpleStringProperty();
- private final BooleanProperty on = new SimpleBooleanProperty();
- public Item(String name, boolean on)
- {
- setName(name);
- setOn(on);
- }
- public final StringProperty nameProperty()
- {
- return this.name;
- }
- public final String getName()
- {
- return this.nameProperty().get();
- }
- public final void setName(final String name)
- {
- this.nameProperty().set(name);
- }
- public final BooleanProperty onProperty()
- {
- return this.on;
- }
- public final boolean isOn()
- {
- return this.onProperty().get();
- }
- public final void setOn(final boolean on)
- {
- this.onProperty().set(on);
- }
- @Override
- public String toString()
- {
- return getName();
- }
- }
- public static void main(String[] args)
- {
- launch(args);
- }
- public void removeItem(ListView listView)
- {
- listView.getItems().removeIf((t) -> {
- return ((Item) t).getName().equals("Item 9");
- });
- }
- }
- import com.jfoenix.controls.JFXCheckBox;
- import com.jfoenix.controls.JFXListView;
- import java.net.URL;
- import java.util.ResourceBundle;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.control.Button;
- import javafx.scene.control.ListView;
- /**
- *
- * @author sedri
- */
- public class FXMLDocumentController implements Initializable {
- @FXML
- JFXListView listview;
- @FXML ListView<String> lvAddNew;
- @FXML Button btnAddNew;
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- // TODO
- for(int i = 1; i < 100; i++)
- {
- JFXCheckBox tempJFXCheckBox = new JFXCheckBox("item " + i);
- tempJFXCheckBox.selectedProperty().addListener((obs, oldValue, newValue)->{
- System.out.println(newValue);
- if(newValue)
- {
- listview.getItems().remove(tempJFXCheckBox);
- lvAddNew.getItems().add(tempJFXCheckBox.getText());
- }
- });
- listview.getItems().add(tempJFXCheckBox);
- }
- }
- @FXML private void handleBtnAddNew(ActionEvent event)
- {
- //Remove selected item
- String tempList = lvAddNew.getSelectionModel().getSelectedItem();
- lvAddNew.getItems().remove(tempList);
- listview.getItems().add(new JFXCheckBox(tempList));
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <?import com.jfoenix.controls.JFXListView?>
- <?import javafx.scene.control.Button?>
- <?import javafx.scene.control.ListView?>
- <?import javafx.scene.layout.AnchorPane?>
- <?import javafx.scene.layout.VBox?>
- <AnchorPane id="AnchorPane" prefHeight="700.0" prefWidth="320" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication2.FXMLDocumentController">
- <children>
- <VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
- <children>
- <JFXListView fx:id="listview" />
- <ListView fx:id="lvAddNew" prefHeight="200.0" prefWidth="200.0" />
- <Button fx:id="btnAddNew" mnemonicParsing="false" onAction="#handleBtnAddNew" text="Add New" />
- </children>
- </VBox>
- </children>
- </AnchorPane>
- yourCheckBox.setID("yourIdHere");
- listView.getItems().removeIf(checkBox -> "yourIdHere".equals(checkBox.getId()));
- CheckBox yourCheckBox = new CheckBox();
- // ...
- listView.getItems().remove(yourCheckBox);
- ListView<CheckBox> listView = new ListView<>();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement