我正在尝试添加一个带有fxml的新选项卡
我正在尝试这段代码:
Tab sd=new Tab("Customeradd");
sd.setContent(Source.sourceFor("","Customeradd.fxml"));
tabpanel.getTabs().add(sd);
Run Code Online (Sandbox Code Playgroud)
我在网上得到语法错误 sd.setContent(Source.sourceFor("","Customeradd.fxml"));,tabpanel是我的TabPane.
错误看起来像

请帮帮我
我在网格窗格中的FXML文件中定义了3个标签.我试图阅读以下XML文件并在网格窗格中显示文件中的标签.XML文件中的数值表示行和列位置.
<data>
<lbl1>0,0</lbl1>
<lbl2>0,1</lbl2>
<lbl3>0,2</lbl3>
</data>
Run Code Online (Sandbox Code Playgroud)
我已将所有元素添加到HashMap中,然后检索它以进行显示.首先,我逐一添加了所有三个标签,如下所示:
hm.put("lbl1", eElement.getElementsByTagName("lbl1").item(0).getTextContent());
hm.put("lbl2", eElement.getElementsByTagName("lbl2").item(0).getTextContent());
hm.put("lbl3", eElement.getElementsByTagName("lbl3").item(0).getTextContent());
Run Code Online (Sandbox Code Playgroud)
然后我按如下方式显示它们:
grid.add(lbl1, Integer.parseInt(hm.get("lbl1").toString().split(",")[0]),Integer.parseInt(hm.get("lbl1").toString().split(",")[1]));
grid.add(lbl2, Integer.parseInt(hm.get("lbl2").toString().split(",")[0]),Integer.parseInt(hm.get("lbl2").toString().split(",")[1]));
grid.add(lbl3, Integer.parseInt(hm.get("lbl3").toString().split(",")[0]),Integer.parseInt(hm.get("lbl3").toString().split(",")[1]));
Run Code Online (Sandbox Code Playgroud)
上面的代码运行良好,没有任何问题,我可以看到网格上的标签.
现在,我没有逐个添加标签,而是通过'for'循环在一个语句中添加了所有标签,如下所示:
if (!eElement.getTagName().toString().equals("data"))
hm.put(eElement.getTagName(), eElement.getTextContent());
Run Code Online (Sandbox Code Playgroud)
如果我尝试显示标签,例如:
grid.add(hm.get("lbl1"),0,0);
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:不兼容的类型 - 对象无法转换为Node.
如果我试图强制转换:
grid.add((javafx.scene.Node) hm.get("lbl1"),0,0);
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:java.lang.ClassCastException:java.lang.String无法强制转换为javafx.scene.Node
如果我打印hashmap条目,则显示以下输出:
lbl1 = 0,0,lbl2 = 0,1,lbl3 = 0.2
如何解决这个错误?有没有其他方法可以在一个语句中添加所有元素然后显示它们?
我有一个FXML文件,我用它来允许用户输入请求.现在我只是把它放在一个新的阶段并且做到了Stage.show().我不希望它出现在一个新窗口中,表现得更像一个ContextMenu.
看看ContextMenu课程,似乎我不能根据FXML文件设置内容.有没有办法用ContextMenu或者Popup或其他一些我不知道的类来做到这一点?
我在Mac上使用Eclipse开发我的JavaFX应用程序。我已经用ant build和e(fx)clipse插件很好地将其打包为dmg。
但是,我现在需要使该应用程序成为exe。到目前为止,我发现的所有教程和帮助都表明您需要Inno Setup,但是该程序仅适用于Windows,而我使用的是Mac。
我应该怎么做?
任何帮助表示赞赏!
我为按钮设置了工具提示,但是它看起来太小(字体大小),我怎么可以将其放大?我试过了myTooltip.setFont(new Font(20)),但是为什么不起作用,为什么?如何使字体变大?谢谢大家!
我在GUI上有两个DatePickers和一个Button。每当第一个datePicker的日期不早于第二个datePicker的日期时,就需要禁用该按钮。即before是false在下面的代码片段:
LocalDate date1 = dpFromDate.getValue();
LocalDate date2 = dpToDate.getValue();
boolean before = date1.isBefore(date2);
button.setDisable(!before);
Run Code Online (Sandbox Code Playgroud)
使用Bindings API。
BooleanBinding bb = ???;
button.disableProperty().bind(bb);
Run Code Online (Sandbox Code Playgroud)
这是我的工作解决方案,但我相信有一个更好的API可以处理这种情况:
BooleanBinding bb = Bindings.selectInteger(dpFromDate.valueProperty(), "year")
.greaterThanOrEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "year"));
bb = bb.or(
Bindings.selectInteger(dpFromDate.valueProperty(), "year")
.isEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "year"))
.and(Bindings.selectInteger(dpFromDate.valueProperty(), "monthValue")
.greaterThanOrEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "monthValue")))
);
bb = bb.or(
Bindings.selectInteger(dpFromDate.valueProperty(), "year")
.isEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "year"))
.and(Bindings.selectInteger(dpFromDate.valueProperty(), "monthValue")
.isEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "monthValue")))
.and(Bindings.selectInteger(dpFromDate.valueProperty(), "dayOfMonth")
.greaterThanOrEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "dayOfMonth")))
);
Run Code Online (Sandbox Code Playgroud) 我的InvalidationListener有问题.它在SimpleStringProperty上设置为Listener.但它仅用于SimpleStringProperty的第一次更改.我进入调试模式并在调用SimpleStringProperty :: set的行上创建了一个断点,它开始工作,直到我再次删除了断点.
我做了一个简短的可执行示例程序,它模拟使用计时器修改SimpleStringProperty.您可以在没有断点的情况下运行程序一次,并且在此行有一次断点:property.set(value);
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Main extends Application {
private SimpleStringProperty property;
private int counter;
@Override
public void start(Stage stage) {
// open a window to avoid immediately termination
stage.setWidth(800);
stage.setHeight(600);
BorderPane pane = new BorderPane();
stage.setScene(new Scene(pane));
stage.show();
// create a SimpleObjectProperty
property = new SimpleStringProperty();
property.addListener(observable ->
System.out.println("New value is: " + counter)
);
counter = 0;
// create timer …Run Code Online (Sandbox Code Playgroud) 是否可以在任意节点/区域/窗格上执行渐渐变浅的简单背景“闪光”效果?
我只想在VBox(包含标签)上显示微妙/简短的红色/白色“闪光”效果,以在标签值更改时引起注意。
编辑:到目前为止,我发现的所有这种性质的示例似乎都使用“ Shape”(这是一个Node),但是VBox或Pane当然不是Shape,因此对我没有太大帮助。在VBox上调用getShape()只会返回一个null,所以这无济于事(我想还没有执行布局代码)。
编辑2:此ALMOST起作用,但此悬挂效果似乎完全覆盖了(我认为)VBox中的所有内容,包括文本Label。
ColorInput effect = new ColorInput(0, 0, 900, 25, Paint.valueOf("#FFDDDD"));
Timeline flash = new Timeline(
new KeyFrame(Duration.seconds(0.4), new KeyValue(effect.paintProperty(), Paint.valueOf("#EED9D9"))),
new KeyFrame(Duration.seconds(0.8), new KeyValue(effect.paintProperty(), Paint.valueOf("#E0DDDD"))),
new KeyFrame(Duration.seconds(1.0), new KeyValue(effect.paintProperty(), Paint.valueOf("#DDDDDD"))));
vbox.setEffect(effect);
flash.setOnFinished(e -> vbox.setEffect(null));
flash.play();
Run Code Online (Sandbox Code Playgroud) 我正在使用JavaFX,并且想自定义按钮。我看到了可以样式化的几个特征。在他们当中,我发现了两个我不认识的人。
.button {
-fx-padding: 5 22 5 22;
-fx-border-color: #121212;
-fx-border-width: 2;
-fx-border-radius: 5;
-fx-background-radius: 0;
-fx-background-color: #555555;
-fx-font-family: "Segoe UI", Helvetica, Arial, sans-serif;
-fx-font-size: 11pt;
-fx-text-fill: #d8d8d8;
-fx-background-insets: 0 0 0 0, 0, 1, 2;
}
Run Code Online (Sandbox Code Playgroud)
这两个属性是什么:
-fx-background-insets: 0 0 0 0, 0, 1, 2;
Run Code Online (Sandbox Code Playgroud)
和
-fx-background-radius: 0;
Run Code Online (Sandbox Code Playgroud)
我看到了,但这对我来说是非常模糊的。
我想双向绑定两个DoubleProperty,但不是真正的1:1,例如以1:1.2的比例绑定。
我需要类似的东西:
DoubleProperty x;
DoubleProperty y;
x.bindBidirectional(y.multiply(1.2));
Run Code Online (Sandbox Code Playgroud)
因此,每次设置x的值时,y值应为x * 1.2 ,每次设置y值时,x值应为y / 1.2
我该怎么做?