JavaFX警报对话框
我正在尝试在javaFX中创建警报弹出窗口。然而,我可以看到OK按钮是英文的,但是CANCEL按钮是用韩语表示的,比如。请让我知道如何用英语制作取消按钮。 这是我代码的一部分:JavaFX警报对话框,java,javafx,scenebuilder,Java,Javafx,Scenebuilder,我正在尝试在javaFX中创建警报弹出窗口。然而,我可以看到OK按钮是英文的,但是CANCEL按钮是用韩语表示的,比如。请让我知道如何用英语制作取消按钮。 这是我代码的一部分: Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.setTitle("Message"); alert.setHeaderText("Are you sure you want to clear all nodes?&q
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Message");
alert.setHeaderText("Are you sure you want to clear all nodes?");
Optional<ButtonType> result = alert.showAndWait();
if (result.get().equals(ButtonType.OK)) {
gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
bst.clear();
height = 20;
width = 740;
ratiowidth = 740;
}else if (result.get().equals(ButtonType.NO)) {
alert.close();
}
Alert-Alert=新警报(Alert.AlertType.CONFIRMATION);
警报。设置标题(“消息”);
setHeaderText(“确实要清除所有节点吗?”);
可选结果=alert.showAndWait();
如果(result.get().equals(ButtonType.OK)){
gc.clearRect(0,0,canvas.getWidth(),canvas.getHeight());
bst.clear();
高度=20;
宽度=740;
比值宽度=740;
}else if(result.get().equals(ButtonType.NO)){
alert.close();
}
欢迎来到StackOverflow!:)
你能检查一下你的默认语言环境吗?因为我的默认值是“en-en”,并且开箱即用,所以我得到值“OK”和“Cancel”按钮。但是如果我在应用程序的开头加上这一行,那么我的字符就会和你的相似,请看附件中的截图
Locale.setDefault(new Locale("ja", "Japan"));
请运行以下代码,使按钮内有英文文本
我的POC申请代码为:
Main.java
package sample;
import javafx.application.Application;
import javafx.scene.control.Alert;
import javafx.stage.Stage;
import java.util.Locale;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
//Locale.setDefault(new Locale("ja", "Japan"));
Locale.setDefault(new Locale("en", "English"));
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Message");
alert.setHeaderText("Are you sure you want to clear all nodes?");
}
public static void main(String[] args) {
launch(args);
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>al.musi.jacek</groupId>
<artifactId>javafx-alert-dialog</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>15.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-fxml -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>15.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.5</version>
<configuration>
<mainClass>C:\Users\re\Documents\GitHub\javafx-alert-dialog\src\main\java\sample\Main.java</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
4.0.0
穆西·雅切克
javafx警报对话框
1.0-快照
11
11
org.openjfx
javafx控件
15.0.1
org.openjfx
javafx-fxml
15.0.1
org.openjfx
javafxmaven插件
0.0.5
C:\Users\re\Documents\GitHub\javafx警报对话框\src\main\java\sample\main.java
欢迎来到StackOverflow!:)
你能检查一下你的默认语言环境吗?因为我的默认值是“en-en”,并且开箱即用,所以我得到值“OK”和“Cancel”按钮。但是如果我在应用程序的开头加上这一行,那么我的字符就会和你的相似,请看附件中的截图
Locale.setDefault(new Locale("ja", "Japan"));
请运行以下代码,使按钮内有英文文本
我的POC申请代码为:
Main.java
package sample;
import javafx.application.Application;
import javafx.scene.control.Alert;
import javafx.stage.Stage;
import java.util.Locale;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
//Locale.setDefault(new Locale("ja", "Japan"));
Locale.setDefault(new Locale("en", "English"));
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Message");
alert.setHeaderText("Are you sure you want to clear all nodes?");
}
public static void main(String[] args) {
launch(args);
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>al.musi.jacek</groupId>
<artifactId>javafx-alert-dialog</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>15.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-fxml -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>15.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.5</version>
<configuration>
<mainClass>C:\Users\re\Documents\GitHub\javafx-alert-dialog\src\main\java\sample\Main.java</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
4.0.0
穆西·雅切克
javafx警报对话框
1.0-快照
11
11
org.openjfx
javafx控件
15.0.1
org.openjfx
javafx-fxml
15.0.1
org.openjfx
javafxmaven插件
0.0.5
C:\Users\re\Documents\GitHub\javafx警报对话框\src\main\java\sample\main.java
另一个答案太长了。你只需要
Locale.setDefault(Locale.ENGLISH);
在创建对话框之前的任何位置,最好是在main或start方法的顶部。另一个答案太长了。你只需要
Locale.setDefault(Locale.ENGLISH);
在创建对话框之前的任何位置,最好在main或start方法的顶部