我有这个组合框,可将对象列表插入组合框中:
private List<ListGroupsObj> lisGroups;
public static class ListGroupsObj
{
private int groupId;
private String groupName;
public static ListGroupsObj newInstance()
{
return new ListGroupsObj();
}
public ListGroupsObj()
{
}
public ListGroupsObj groupId(int groupId)
{
this.groupId = groupId;
return this;
}
public ListGroupsObj groupName(String groupName)
{
this.groupName = groupName;
return this;
}
public int getGroupId()
{
return groupId;
}
public String getGroupName()
{
return groupName;
}
// @Override
// public String toString()
// {
// return serverName;
// }
}
ListGroupsObj ob …Run Code Online (Sandbox Code Playgroud) 由于缺少教程和以下问题的示例不完整,我决定写这个问题。如果这个问题的答案成为解决类似问题的有效例子,我会很高兴。
任务
让我们使用JavaFX技术(使用FXML作为该技术的一部分来制作图形视图)制作一个GUI 应用程序,例如显示用户集合和每个用户的汽车集合。让我们还使用JavaFX 属性和bindig机制将模型(数据)与 GUI 同步。
执行
我从为用户和汽车创建类开始。
用户.java
package example;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class User {
public StringProperty firstName;
public StringProperty lastName;
private ObservableList<Car> cars;
public User(String firstName, String lastName, Car[] cars) {
this.firstName = new SimpleStringProperty(firstName);
this.lastName = new SimpleStringProperty(lastName);
this.cars = FXCollections.observableArrayList(cars);
}
public String getFirstName() …Run Code Online (Sandbox Code Playgroud) 我在将VBox作为子属性插入MenuButton时遇到问题,因为我必须在赋值中执行此操作.到目前为止,我已经想出了这个:
<MenuButton fx:id="mb" mnemonicParsing="false" text="" GridPane.columnIndex="1" GridPane.rowIndex="3">
<items>
<VBox prefHeight="200.0" prefWidth="100.0" >
<Button text="Button" GridPane.columnIndex="0" GridPane.rowIndex="0" />
<RadioButton text="RadioButton" GridPane.columnIndex="1" GridPane.rowIndex="0" />
<Button text="Click Me" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<ComboBox GridPane.columnIndex="0" GridPane.rowIndex="1" />
<Slider GridPane.columnIndex="0" GridPane.rowIndex="2" />
<CheckBox text="CheckBox" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField prefWidth="200.0" GridPane.columnIndex="0" GridPane.rowIndex="3" />
</VBox>
</items>
</MenuButton>Run Code Online (Sandbox Code Playgroud)
但是我收到了以下错误:
Caused by: java.lang.IllegalArgumentException: Unable to coerce VBox@13f6e35e to class javafx.scene.control.MenuItem.
Run Code Online (Sandbox Code Playgroud)
有人可以澄清我的错误或帮助我解决它吗?谢谢你的帮助.
我想知道将JavaFX TableView数据收集到集合的最佳和最有效的方法。我想获取JavaFX TableView内的所有行。
如何在 JavaFx 中将 textField 与其他 textField 绑定。例如
textFieldTotal.textProperty.bind(Bindings.multiply(textFieldAmount.textProperty,
textFieldPrice.textProperty));
Run Code Online (Sandbox Code Playgroud) 我在JavaFX中有一个简单的密码生成器。每当我单击该按钮时,都会生成一个密码,但是当我单击应用程序区域中的其他位置时,该按钮也会响应。如何减少点击面积?
主要
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("/sample/main.fxml"));
primaryStage.setTitle("Password Generator");
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.setMaxWidth(610.0);
primaryStage.setMaxHeight(450.0);
primaryStage.setMinWidth(600.0);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)
Main.fxml
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("/sample/main.fxml"));
primaryStage.setTitle("Password Generator");
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.setMaxWidth(610.0);
primaryStage.setMaxHeight(450.0);
primaryStage.setMinWidth(600.0);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Run Code Online (Sandbox Code Playgroud) 我是Java(和一般编程)的新手,正在通过将基本电子表格转换为javafx应用程序来学习。为此,我正在使用:Java和JavaFX 12 FXML和Scenebuilder for GUI
大约有10个输入字段,它们不能为空(应用程序崩溃,因为getText似乎在空白字段上失败)。
我编写了堆叠的if语句来检查空白字段,然后打印错误消息(如果有的话),并返回以停止该过程而不会崩溃该应用程序。
switch语句似乎没有if语句更好。
有没有办法用更少的代码行做到这一点?
package SteelDesign_BoltedConnection;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextArea;
import javafx.event.ActionEvent;
public class mainController {
//Header details
@FXML private TextField refNo;
@FXML private TextField jobDesc;
@FXML private TextField author;
@FXML private DatePicker date;
//Design data
@FXML private TextField desShear;
@FXML private TextField boltSize;
@FXML private TextField boltGrade;
@FXML private TextField tensStrengthBolt;
@FXML private TextField noBolts;
@FXML private TextField shearPlanes;
@FXML private TextField edgeDist;
@FXML private TextField plyThick;
@FXML private TextField …Run Code Online (Sandbox Code Playgroud) 我正在用 GUI 做数独项目。我有一个二维数组来保存 9x9 网格中的数字。我想更改保存非 0 数组值的文本字段的背景颜色。这是我操作文本字段和 GUI 图片的代码的一部分。例如在第一个 3x3 网格中,5,4 和 1 位数字背景为灰色,但 9 不是。问题是什么?请帮忙。谢谢你。
public class Controller {
private Board board;
private TextField[] tfs;
@FXML GridPane gridPane;
@FXML Button startButton;
@FXML Button stopButton;
@FXML Label timeLabel;
private final IntegerProperty timeSeconds = new SimpleIntegerProperty(0);
private Timeline timeline;
public void initialize() throws IOException {
board = new Board();
tfs = new TextField[81];
int c = 0;
for (int i = 0; i < 9; i++) {
for (int j = …Run Code Online (Sandbox Code Playgroud) 我希望用户等待我的方法调用下载文件(这可能需要大约 2 到 3 分钟)完成。我为方法调用创建了一个新线程并在方法内部调用它run()。根据返回值,应该显示一条消息,无论是成功还是错误。因此我不得不使用join(). 但这仍然冻结,因为 UI 仍在等待方法调用完成。我怎样才能克服这个问题?(基本上,我需要使用一个线程让 UI 不冻结,同时我想根据方法的返回值显示一条消息)
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
processMsg.setText("Do not close. This may take few minutes...");
Thread t1 = new Thread(new Runnable(){
@Override
public void run() {
try {
ret = /*Method-call-which-takes-long-time*/
} catch (IOException ex) {
Logger.getLogger(JavaFXApplication1.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(JavaFXApplication1.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
t1.start();
try {
t1.join();
} catch (InterruptedException ex) {
Logger.getLogger(JavaFXApplication1.class.getName()).log(Level.SEVERE, null, ex);
}
if …Run Code Online (Sandbox Code Playgroud) 我想使用 JavaFX 显示 .txt 报告文件中的数据。在我的代码中,我尝试使用标签和 Vbox 在 GUI 中以多种格式显示信息到场景。但是,我将结果输出为 GUI 而不是控制台,结果很糟糕。我试图研究我的问题,但找不到解决问题所需的信息。
这是我需要使用 JavaFX 显示为 GUI 应用程序的报告:
这是我的代码作为 GUI 显示的内容:
这是我的源代码:
package sample;
public class CustomerSale {
// Details of reports
private String zipCodeExtension;
private int customerNumber;
private String customerName;
private int purchaseDate;
private String make;
private int purchasePrice;
private int yearOfVehicle;
private int satisfactionRating;
// Create constructor argument
public CustomerSale(String zipCodeExtension, int customerNumber, String customerName,
int purchaseDate, String make, int purchasePrice,
int yearOfVehicle, int satisfactionRating) {
this.zipCodeExtension = zipCodeExtension;
this.customerNumber …Run Code Online (Sandbox Code Playgroud)