Customize ListView in JavaFX with FXML

前端 未结 3 613
無奈伤痛
無奈伤痛 2020-11-29 22:05

I want to make a customize list view in javafx. Here I need to bind multiple component in list cell as follow, like one label, one textfield, one button under one HBox and

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 22:12

    The answer by Anvay for some reason didnt work for me, what i had to do to fix it was just some very small tweaks:

    1. remove import data statement from listCellItem.fxml
    2. as the comment below the post states in Data.java put hBox = fmxlLoader.load()
    3. I also had a main class (intellij auto generated).

      public class MainMain extends Application {
      
      @Override
      public void start(Stage primaryStage) throws Exception{
      
      FXMLLoader fxmlLoader = new 
      FXMLLoader(getClass().getResource("MainController.fxml"));
      try
      {
          Parent root = fxmlLoader.load();
      
          Scene scene = new Scene(root);
          primaryStage.setScene(scene);
          primaryStage.setTitle("Title");
          primaryStage.show();
      }
      catch (IOException e)
      {
          throw new RuntimeException(e);
      }
      }
      
      
      
      public static void main(String[] args) {
          launch(args);
      }
      

    I know this was probably obvious for most of the experts here, but these issues perplexed me for hours while i was debugging.

提交回复
热议问题