Advertisement
Guest User

Untitled

a guest
May 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.15 KB | None | 0 0
  1. ArrayList<String> ServiceToDelete = R.OffrirService();
  2. List<String> seup = se.stream().filter(elem -> !ServiceToDelete.contains(elem)).collect(Collectors.toList());
  3. for (int x = 0; x < seup.size(); x++) {
  4. String g = seup.get(x);
  5. li_se.getItems().removeIf((t) -> {
  6. return ((JFXCheckBox) t).getText().equals(g);
  7. });
  8. //System.out.println(li_se.getItems().indexOf(ServiceToDelete.get(x)));
  9. }
  10.  
  11. // observe item's on property and display message if it changes:
  12. item.onProperty().addListener((obs, wasOn, isNowOn) -> {
  13. System.out.println(item.getName() + " changed on state from " + wasOn + " to " + isNowOn);
  14. if (isNowOn) {
  15. listView.getItems().remove(item);
  16. }
  17. });
  18.  
  19. listView.getItems().removeIf((t) -> {
  20. return ((Item) t).getName().equals("Item 9");
  21. });
  22.  
  23. import javafx.application.Application;
  24. import javafx.beans.property.BooleanProperty;
  25. import javafx.beans.property.SimpleBooleanProperty;
  26. import javafx.beans.property.SimpleStringProperty;
  27. import javafx.beans.property.StringProperty;
  28. import javafx.scene.Scene;
  29. import javafx.scene.control.ListView;
  30. import javafx.scene.control.cell.CheckBoxListCell;
  31. import javafx.scene.layout.BorderPane;
  32. import javafx.stage.Stage;
  33.  
  34. public class ListViewWithCheckBox extends Application
  35. {
  36.  
  37. @Override
  38. public void start(Stage primaryStage)
  39. {
  40. ListView<Item> listView = new ListView<>();
  41. for (int i = 1; i <= 20; i++) {
  42. Item item = new Item("Item " + i, false);
  43.  
  44. // observe item's on property and display message if it changes:
  45. item.onProperty().addListener((obs, wasOn, isNowOn) -> {
  46. System.out.println(item.getName() + " changed on state from " + wasOn + " to " + isNowOn);
  47. if (isNowOn) {
  48. listView.getItems().remove(item);
  49. }
  50. });
  51.  
  52. listView.getItems().add(item);
  53. }
  54.  
  55. listView.setCellFactory(CheckBoxListCell.forListView((Item item) -> item.onProperty()));
  56.  
  57. removeItem(listView);
  58.  
  59. BorderPane root = new BorderPane(listView);
  60. Scene scene = new Scene(root, 250, 400);
  61. primaryStage.setScene(scene);
  62. primaryStage.show();
  63.  
  64. }
  65.  
  66. public static class Item
  67. {
  68.  
  69. private final StringProperty name = new SimpleStringProperty();
  70. private final BooleanProperty on = new SimpleBooleanProperty();
  71.  
  72. public Item(String name, boolean on)
  73. {
  74. setName(name);
  75. setOn(on);
  76. }
  77.  
  78. public final StringProperty nameProperty()
  79. {
  80. return this.name;
  81. }
  82.  
  83. public final String getName()
  84. {
  85. return this.nameProperty().get();
  86. }
  87.  
  88. public final void setName(final String name)
  89. {
  90. this.nameProperty().set(name);
  91. }
  92.  
  93. public final BooleanProperty onProperty()
  94. {
  95. return this.on;
  96. }
  97.  
  98. public final boolean isOn()
  99. {
  100. return this.onProperty().get();
  101. }
  102.  
  103. public final void setOn(final boolean on)
  104. {
  105. this.onProperty().set(on);
  106. }
  107.  
  108. @Override
  109. public String toString()
  110. {
  111. return getName();
  112. }
  113.  
  114. }
  115.  
  116. public static void main(String[] args)
  117. {
  118. launch(args);
  119. }
  120.  
  121. public void removeItem(ListView listView)
  122. {
  123. listView.getItems().removeIf((t) -> {
  124. return ((Item) t).getName().equals("Item 9");
  125. });
  126. }
  127. }
  128.  
  129. import com.jfoenix.controls.JFXCheckBox;
  130. import com.jfoenix.controls.JFXListView;
  131. import java.net.URL;
  132. import java.util.ResourceBundle;
  133. import javafx.event.ActionEvent;
  134. import javafx.fxml.FXML;
  135. import javafx.fxml.Initializable;
  136. import javafx.scene.control.Button;
  137. import javafx.scene.control.ListView;
  138.  
  139. /**
  140. *
  141. * @author sedri
  142. */
  143. public class FXMLDocumentController implements Initializable {
  144.  
  145. @FXML
  146. JFXListView listview;
  147. @FXML ListView<String> lvAddNew;
  148. @FXML Button btnAddNew;
  149.  
  150.  
  151. @Override
  152. public void initialize(URL url, ResourceBundle rb) {
  153. // TODO
  154. for(int i = 1; i < 100; i++)
  155. {
  156. JFXCheckBox tempJFXCheckBox = new JFXCheckBox("item " + i);
  157. tempJFXCheckBox.selectedProperty().addListener((obs, oldValue, newValue)->{
  158. System.out.println(newValue);
  159. if(newValue)
  160. {
  161. listview.getItems().remove(tempJFXCheckBox);
  162. lvAddNew.getItems().add(tempJFXCheckBox.getText());
  163. }
  164. });
  165.  
  166. listview.getItems().add(tempJFXCheckBox);
  167. }
  168. }
  169.  
  170. @FXML private void handleBtnAddNew(ActionEvent event)
  171. {
  172. //Remove selected item
  173. String tempList = lvAddNew.getSelectionModel().getSelectedItem();
  174. lvAddNew.getItems().remove(tempList);
  175. listview.getItems().add(new JFXCheckBox(tempList));
  176. }
  177. }
  178.  
  179. <?xml version="1.0" encoding="UTF-8"?>
  180.  
  181. <?import com.jfoenix.controls.JFXListView?>
  182. <?import javafx.scene.control.Button?>
  183. <?import javafx.scene.control.ListView?>
  184. <?import javafx.scene.layout.AnchorPane?>
  185. <?import javafx.scene.layout.VBox?>
  186.  
  187. <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">
  188. <children>
  189. <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">
  190. <children>
  191. <JFXListView fx:id="listview" />
  192. <ListView fx:id="lvAddNew" prefHeight="200.0" prefWidth="200.0" />
  193. <Button fx:id="btnAddNew" mnemonicParsing="false" onAction="#handleBtnAddNew" text="Add New" />
  194. </children>
  195. </VBox>
  196. </children>
  197. </AnchorPane>
  198.  
  199. yourCheckBox.setID("yourIdHere");
  200.  
  201. listView.getItems().removeIf(checkBox -> "yourIdHere".equals(checkBox.getId()));
  202.  
  203. CheckBox yourCheckBox = new CheckBox();
  204.  
  205. // ...
  206.  
  207. listView.getItems().remove(yourCheckBox);
  208.  
  209. ListView<CheckBox> listView = new ListView<>();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement