例如,如果我要添加一行代码,例如-
hbox.getChildren().add(calculateButton);
Run Code Online (Sandbox Code Playgroud)
.getChildren 有什么意义?如果在程序中不使用它会发生什么?
我总是在很多代码中看到这一点:
String s;
if (s == null || s.isEmpty()) {
//do something
}
Run Code Online (Sandbox Code Playgroud)
但这还不够
String s;
if (s.isEmpty()) {
//do something
}
Run Code Online (Sandbox Code Playgroud)
我很好奇,尤其是当我检查 JavaFX TextField 是否为空时。
我需要将日期属性传递给 setCellValueFactory ,这是我的 seters 和 geters 的代码Persona class,正确的方法是什么,我认为我在正确的声明中遇到了问题,所以我在这里需要一个真正的方向,我需要在java.sql.date类中声明一些日期,可以参考一下吗?任何想法?。请在这里提供一点帮助。
package application;
import java.time.LocalDate;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class Persona {
private StringProperty nombres;
private StringProperty apellidos;
private IntegerProperty id_cliente;
private ObjectProperty <LocalDate>fechacliente;
public Persona ( String nombres, String apellidos, Integer id_cliente, Object fechacliente) {
this.nombres= new SimpleStringProperty (nombres);
this.apellidos= new SimpleStringProperty ( apellidos);
this.id_cliente=new SimpleIntegerProperty (id_cliente);
this.fechacliente= new SimpleObjectProperty<LocalDate>();
}
public Object getFecha() {
return fechacliente.get();
}
public void setFecha(Object …Run Code Online (Sandbox Code Playgroud) 当尝试下面的代码并重新打开窗口时,ListView 工具提示未显示。
Tooltip tooltip1 = new Tooltip(timeToday());
listView.setTooltip(tooltip1);
Run Code Online (Sandbox Code Playgroud) 我正在尝试将数据填充到我的表视图中,一切看起来都很好,但仍然没有显示数据。这是代码。一切似乎都很好,但桌面视图没有显示任何内容。连眼睛都不眨一下……
public class MainPage implements Initializable {
@FXML
private AnchorPane root;
@FXML
private Button main_LogOut;
@FXML
private ComboBox<?> main_Clients;
@FXML
private ComboBox<?> main_Users;
@FXML
private TableView<customerDetails> table;
@FXML
private TableColumn<customerDetails, String> clientId;
@FXML
private TableColumn<customerDetails, String> clientName;
@FXML
private TableColumn<customerDetails, String> clientEmail;
@FXML
private TableColumn<customerDetails, String> clientRequirement;
@SuppressWarnings("unchecked")
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub
clientId.setCellValueFactory(new PropertyValueFactory<customerDetails,String> ("Id"));
clientName.setCellValueFactory(new PropertyValueFactory<customerDetails, String>("name"));
clientEmail.setCellValueFactory(new PropertyValueFactory<customerDetails, String>("email"));
clientRequirement.setCellValueFactory(new PropertyValueFactory<customerDetails, String>("Requirements"));
table=new TableView<customerDetails>();
table.setItems(getClients());
table.getColumns().addAll(clientId,clientName,clientEmail,clientRequirement);
}
@FXML
void …Run Code Online (Sandbox Code Playgroud) 我需要将 BorderPane 包含在 StackPane 内。用于使用 JFX 对话框。JFXDialog() 的第一个参数必须是 StackPane 变量。我无法传递 BorderPane 变量来代替它。所以我尝试围绕 BorderPane 创建一个新的 StackPane 标签
示例.fxml
<StackPane fx:id="rootPane" xmlns="http://javafx.com/javafx/8.0.112-ea"
xmlns:fx="http://javafx.com/fxml/1">
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="600.0" style="-fx-background-color: #181818;" xmlns="http://javafx.com/javafx/16"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.SampleController">
<left>
.........
.........
</BorderPane>
</StackPane>
Run Code Online (Sandbox Code Playgroud)
但是在添加此标签后,Sample.fxml 无法使用 SceneBuilder 打开,当我尝试运行 JavaFx Main 类时,我收到此错误。
javafx.fxml.LoadException: StackPane is not a valid type.
Run Code Online (Sandbox Code Playgroud)
示例控制器.java
....
public class SampleController implements Initializable {
...
@FXML
private StackPane rootPane;
@FXML
private void migrateButtonAction(ActionEvent event){
JFXDialogLayout dialogLayout = new JFXDialogLayout();
JFXDialog dialog = new JFXDialog(rootPane,dialogLayout, …Run Code Online (Sandbox Code Playgroud) 因此,正如帖子标题所述,我正在寻求一种方法,可以将使用 FileChooser 上传到项目目录中的文件表示出来。
更具体地说,我正在上传图像,我想将它们保存在我的项目中,以便将来使用它们。这是一个示例代码:
控制器:
package org.example;
import javafx.fxml.FXML;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.FileChooser;
import java.io.File;
public class PrimaryController {
@FXML
private ImageView image;
@FXML
void handleUploadImage() {
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Image Files", "*.jpg", "*.jpeg", "*.png", "*.svg"));
File file = fileChooser.showOpenDialog(null);
if (file != null) {
image.setImage(new Image(String.valueOf(file)));
} else {
System.out.println("It's null");
}
}
}
Run Code Online (Sandbox Code Playgroud)
FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: …Run Code Online (Sandbox Code Playgroud) 我有一个HBox内部 a VBox,虽然大多数问题似乎都在问如何使用它所包含的HBox整个宽度VBox,但我要求相反。我的里面有按钮,其HBox数量不断变化,因此HBox应该不断改变它的大小,但是在向 中添加背景颜色后,HBox很明显它占据了 的整个宽度VBox,使其无法居中。
它目前类似于顶部示例,但我需要它类似于底部示例:
并使用
HBox.setHgrow(wordButtonsBox, Priority.NEVER);
Run Code Online (Sandbox Code Playgroud)
也没有改变任何东西..
public class CentreStuff extends Application {
@Override
public void start(Stage primaryStage) {
primaryStage.setScene(new Scene(createContent()));
primaryStage.show();
}
private Region createContent() {
HBox buttonBox1 = new HBox(new Button("Button1"), new Button("Button2"), new Button("Button3"), new Button("Button4"));
buttonBox1.setStyle("-fx-border-color: red;");
VBox results = new VBox(10, buttonBox1);
return results;
}
Run Code Online (Sandbox Code Playgroud) 编辑:我相信我终于找到了问题的正确答案。
原帖:
我目前正在尝试使用 JavaFX 和 EventBus 系统创建一个应用程序。为此,我必须在实例化其他类时将 EventBus 作为构造函数参数传递给它们。但是我不知道如何在使用 FXMLLoader 加载我的 .fxml 文件的同时执行此操作。
我的代码目前看起来像这样:
主班
public class MyApplication extends Application {
public void start(Stage stage) throws Exception {
EventBus eventBus = new EventBus();
>>> Here would be code that creates an Object of MainView, passing eventBus as constructor argument. <<<
Scene scene = new Scene(mainView);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)
这个类继承自 BorderPane,我想使用 fxmlLoader 创建它的对象(我想。我不确定它是否像那样工作)
puplic class MainView extends BorderPane {
private EventBus …Run Code Online (Sandbox Code Playgroud) 我的申请代码
public class Main extends Application {
private static Scene scene;
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlloader = new FXMLLoader(LoginControler.class.getResource("loging.fxml"));
scene = new Scene(fxmlloader.load());
stage.setScene(scene);
stage.setResizable(false);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Run Code Online (Sandbox Code Playgroud)
我试图使用终端在 javafx 应用程序之上运行,但出现此错误。请告诉我我在脚本中是否犯了错误。我已经使用maven-shade-plugin来构建具有依赖项的 jar
root@abc-abc2051A:~# java -jar --module-path /opt/javafx-sdk-11/lib --add-modules javafx.controls myjar-1.0.0-shaded.jar
Error: Invalid or corrupt jarfile /opt/javafx-sdk-11/lib
Run Code Online (Sandbox Code Playgroud)
应用运行环境
javafx ×10
java ×6
fxml ×2
arraylist ×1
filechooser ×1
fxmlloader ×1
methods ×1
scenebuilder ×1
tableview ×1
ubuntu-22.04 ×1