[英]How to change the style of a normal pane (Not layout pane)
well i am new to JavaFx and i haven't been using java for a really long time, so i am having many problems. 好吧,我是JavaFx的新手,而且我已经很长时间没有使用Java了,所以我遇到了很多问题。 And the biggest is how to change the bg of the damn pane.
最大的问题是如何更改该死窗格的bg。
Below is the Controller class 下面是Controller类
//Styling prePane
public class Controller {
//Declaring elements
public Pane prePane;
public Button generate;
public TextArea info;
@FXML
ProgressBar progressBar;
public void onGenerate() throws IOException {
//Styling prePane
prePane=new Pane();
prePane.getStyleClass().add("prePane");
//Creating and embedding progressBar
generate.setDisable(true);
progressBar.setProgress(0);
//Creating task object
Task copyWorker = createWorker();
progressBar.progressProperty().unbind();
progressBar.progressProperty().bind(copyWorker.progressProperty());
copyWorker.messageProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
System.out.println(newValue);
}
});
//Starting task thread
new Thread(copyWorker).start();
//QR Code generation
String details;
info.getParagraphs();
details=String.valueOf(info.getText());
ByteArrayOutputStream out= net.glxn.qrgen.QRCode.from(details).to(ImageType.GIF).stream();
File file=new File("D:\\JavaFXQRGenerator-master\\QrGenerator\\QrCode\\details.jpg");
FileOutputStream fos=new FileOutputStream(file);
fos.write(out.toByteArray());
fos.flush();
}
//Defining the task
public Task createWorker() {
return new Task() {
@Override
protected Object call() throws Exception {
for (int i = 0; i < 10; i++) {
updateProgress(i + 1, 10);
}
return true;
}
};
}
} }
Main Class 主班
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("QR Generator");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
} }
Below the actual Style sheet 在实际的样式表下方
.prePane{
-fx-background-image: url("D:\JavaFXQRGenerator-master\QrGenerator\resources\genPane.jpg");
}
Any kind of help is appreciated. 任何帮助都将受到赞赏。
Assuming the resources
folder is part of your build path, genPane.jpg
will be in the root of the classpath. 假设
resources
文件夹是构建路径的一部分, genPane.jpg
将位于类路径的根目录中。 So the correct path, according to the CSS documentation is just 因此,根据CSS文档 ,正确的路径仅仅是
.prePane{
-fx-background-image: url("/genPane.jpg");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.