It's about JavaFX. When i want to inject fx:id in Scene Builder, i get this warning:
No injectable field found in FXML Controller class for the id 'something'.
I wanted to ignore it, and created a function, but it didn't work either. I created mainController class and added it into my FXML file. Here are my codes...
mainController.java
package main;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.Slider;
public class mainController implements Initializable {
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub
}
@FXML
private ProgressBar pb;
@FXML
private Slider sl;
@FXML
private Label label;
public void changed(ActionEvent event){
}
}
Main.java
package main;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("/fxml/main.fxml"));
Scene scene = new Scene(root, 600, 400);
scene.getStylesheets().add("/fxml/styles/main.css");
ProgressBar pb1 = new ProgressBar();
ProgressBar pb2 = new ProgressBar();
//pb1.
//primaryStage.setResizable(false);
primaryStage.setScene(scene);
primaryStage.setTitle("Something");
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
main.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="main.mainController">
<children>
<BorderPane layoutX="14.0" layoutY="14.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<top>
<ProgressBar fx:id="pb" prefWidth="200.0" progress="0.0" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="30.0" left="30.0" right="30.0" top="30.0" />
</BorderPane.margin>
</ProgressBar>
</top>
<bottom>
<Slider fx:id="sl" onDragDetected="#changed" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="30.0" left="30.0" right="30.0" top="30.0" />
</BorderPane.margin>
</Slider>
</bottom>
</BorderPane>
</children>
</AnchorPane>
I did same things in my old projects, and they work like a charm. But this one seems not to obey me. Thanks in advance...
label
yet I can't find a label in your FXML. And you could write yourchange
-method like:@FXML private void change() {...}
– haisi