I can not display on my listview of java fxml in intellij. I would like anyone to help me by
This is the fxml code:
<pre>="1.0"="UTF-8"
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1">
<children>
<MenuBar layoutY="2.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<ListView fx:id="lista" layoutY="26.0" prefHeight="376.0" prefWidth="248.0" />
</children>
</AnchorPane>
this is the controller code:
<pre>package com.example.helloworldfx;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionMode;
import java.net.URL;
import java.util.ResourceBundle;
public class HelloController implements Initializable {
@FXML
private ListView<String> lista;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
String b = "marcos";
String c = "marcos";
String d = "marcos";
String e = "marcos";
lista = new ListView<>();
lista.getItems().setAll(b, c,d,e);
lista.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
}
}
this is the main class code
package com.example.helloworldfx;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 500, 240);
stage.setTitle("Hello!");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
What I have tried:
I have tried to create the object of linkList however it does not works.