我想在javafx中创建自定义列表视图.在这里,我需要在列表单元格中绑定多个组件,如下所示,例如一个标签,一个文本字段,一个HBox下的一个按钮和两个按钮,一个超链接,另一个HBox中的一个标签,这些HBox属于一个VBox,这个VBox属于单个列表单元格,它将重复并生成一个列表视图.
代码是
<ListView fx:id="ListView" layoutX="0" layoutY="30" prefWidth="600" prefHeight="300">
<HBox fx:id="listBox" alignment="CENTER_LEFT">
<padding><Insets top="5" bottom="5" left="5"></Insets> </padding>
<HBox alignment="CENTER_LEFT" prefWidth="170" minWidth="88">
<Label fx:id="surveyName" text="Field A" styleClass="Name"></Label>
</HBox>
<VBox styleClass="Description" prefWidth="155" minWidth="86">
<HBox>
<HBox styleClass="surveyDesIcon" prefWidth="20" prefHeight="16"></HBox>
<Label fx:id="surveyCode" text="PRW3456HJ"></Label>
</HBox>
<HBox>
<HBox styleClass="DateIcon" prefWidth="20" prefHeight="16"></HBox>
<Label fx:id="Date" text="PRW3456HJ"></Label>
</HBox>
</VBox>
<HBox fx:id="Status" prefWidth="160" minWidth="80">
<Label fx:id="StatusLabel" text="Checking Files.."/>
</HBox>
<HBox fx:id="StatusIcon1" prefWidth="50" prefHeight="50" alignment="CENTER">
<Label styleClass="StatusIcon1" prefWidth="24" prefHeight="24" alignment="CENTER"/>
</HBox>
<HBox fx:id="StatusIcon2" prefWidth="50" prefHeight="50" styleClass="StatusIconBox" alignment="CENTER">
<Hyperlink styleClass="StatusIcon2" prefWidth="24" maxHeight="24" alignment="CENTER"/> …Run Code Online (Sandbox Code Playgroud) 我正在研究JavaFX应用程序.我的所有gui都是.fxml格式化的,通过控制器类来管理所有GUI组件.但是,在加载FXML加载器之前,我在实例化控制器类时遇到了困难.我无法从stackoverflow上的其他人那里找到一个很好的解决方案,因此这不是一个重复的问题.
我实例化控制器类的原因是我想传递一些参数,以便这些参数将显示在GUI中.
我按以下方式加载FXML文件:
/*
* for Work Order button
*/
@FXML
private void pressWorkOrder() throws Exception{
WorkOrderController wo = new WorkOrderController("ashdkjhsahd"); //instantiating constructor
Parent parent = FXMLLoader.load(getClass().getResource("/fxml/WorkOrder.fxml"));
Scene scene = new Scene(parent);
Stage stage = new Stage();
stage.setScene(scene);
stage.setTitle("Word Order");
stage.setResizable(false);
stage.show();
}
Run Code Online (Sandbox Code Playgroud)
这是我的实际Controller类:
public class WorkOrderController implements Initializable{
@FXML
private Button summary;
private String m,n;
public WorkOrderController(String str) {
// TODO Auto-generated constructor stub
m = str;
}
//for testing
public void set(String …Run Code Online (Sandbox Code Playgroud)