我正在寻找一种注册到控制器上的 FXML 组件注入的方法。所以我会有这样的方法
无效 afterComponenetInjection();
一旦注入 FXML 组件,就会触发。
在 JavaFX 2.2 中,我在导入具有 FXML 中定义的自定义单元工厂的自定义组件时遇到问题。假设我的自定义组件如下
public class CustomComponent extends VBox{
public CustomComponent() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("CustomComponent.fxml"));
loader.setRoot(this);
loader.setController(this);
loader.load();
} catch (IOException e ){
throw new RuntimeException(e);
}
}
Run Code Online (Sandbox Code Playgroud)
}
而对应的 FXML 是
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.VBox?>
<?import application.*?>
<?import application.TestFactory?>
<fx:root prefHeight="358.0" prefWidth="260.0" type="VBox" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
<children>
<TableView prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
<columns>
<TableColumn prefWidth="75.0" text="C1" >
<cellFactory>
<TestFactory />
</cellFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="C2" >
<cellFactory>
<TestFactory …Run Code Online (Sandbox Code Playgroud) 我正在做一个项目,我需要你的帮助。
我想知道这是否可以按百分比设置锚板约束,例如
AnchorPane.setLeftAnchor(content1, 35%);
Run Code Online (Sandbox Code Playgroud) 我正在开发一个需要在窗格上移动节点的应用程序。
我最近才开始学习 javaFx 8,所以我对工作流程一无所知,但是虽然我设法让一个工作的可拖动节点代码工作,但它使用 node.setTranslateX() 和 .setTranslateY()。
这一切都很好,直到我尝试使节点对齐到一个网格,该网格将场景区域划分为 10 个高度和宽度细分。
每当我尝试使用模数来进行某种捕捉时,我都会坚持我正在调用翻译转换这一事实。我想自己直接设置节点的坐标。我试过 node.relocate(x,y) 无济于事。至于 node.setX() 或 node.setY()。这些似乎没有多大作用。
所以基本上,我有两个问题:
我当前的代码使用这些方法来拖动节点:
public class Boat extends ImageView {
private int size ;
private String name ;
private Double dragDeltaX, dragDeltaY;
//Constructor etc here//
this.setOnMousePressed(event -> {
this.setCursor(Cursor.CLOSED_HAND);
dragDeltaX = this.getLayoutX() + event.getX();
dragDeltaY = this.getLayoutY() + event.getY();
});
this.setOnMouseReleased(event -> {
this.setCursor(Cursor.OPEN_HAND);
this.relocate(event.getSceneX(), event.getSceneY());
});
this.setOnMouseDragged(event -> {
this.setTranslateX(event.getSceneX() - dragDeltaX);
this.setTranslateY(event.getSceneY() - dragDeltaY);
});
this.setOnMouseEntered(event -> {
this.setCursor(Cursor.OPEN_HAND);
});
}
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助,
我得到了以下变量
List<Pruefvorschrift> listP = new ArrayList<Pruefvorschrift>();
ObservableMap<TestDevice,List<Pruefvorschrift>> testDev = FXCollections.emptyObservableMap();
Run Code Online (Sandbox Code Playgroud)
在一个函数中,我想通过使用lambda表达式填充testDev
//first call REST service and get data
List<TestDevice> test_dev = call.getTestDevice("");
//now do a foreach to add each entry (as key) to the testDev ObservableMap with a empty List (as value)
test_dev.stream().forEach(td ->{
TestDevice t = td;
testDev.put(t, listP);
});
Run Code Online (Sandbox Code Playgroud)
但我得到的只是一个错误
java.util.AbstractMap.put上的java.lang.UnsupportedOperationException(AbstractMap.java:209)
这显然是这一行
testDev.put(t, listP);
Run Code Online (Sandbox Code Playgroud)
也许我误解了新的流api,但我只想填充可观察的地图,其中包含调用的所有结果(键)和一个空的List(稍后将修改的值).有帮助吗?谢谢
在我的应用程序(媒体播放器)上,当应用程序处于全屏模式时,我正在淡出顶部栏和底栏.我也想在延迟几秒后淡出光标.我试过FadeTransition,但它只Node作为参数.
我也试过使用线程.
Platform.runLater(new Runnable()
{
@Override
public void run()
{
try
{
Thread.sleep(2000);
scene.setCursor(Cursor.NONE);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
});
Run Code Online (Sandbox Code Playgroud)
在这里,我只想在延迟两秒后隐藏光标.它工作,但也挂了我的应用程序两秒钟,我不指望.
以两种方式延迟后,我可以通过哪种方式淡出光标?
我正在尝试在Eclipse Maven项目中为我的JavaFX应用程序创建一个可执行jar.
我正在关注这个线程: Eclipse中的Maven的JavaFx应用程序
这个turotial:https://www.youtube.com/watch? v = wbjW8rYlook
我
No plugin found for prefix 'jfx' in the current project and in the plugin groups
在尝试运行目标时遇到错误:jfx:jar
完整构建错误:
[INFO] Scanning for projects...
[INFO] Downloading: https://repo.maven.apache.org/maven2/com/zenjava/javafx-maven-plugin/8.1.2/javafx-maven-plugin-8.1.2.pom
[WARNING] Failed to retrieve plugin descriptor for com.zenjava:javafx-maven-plugin:8.1.2: Plugin com.zenjava:javafx-maven-plugin:8.1.2 or one of its dependencies could not be resolved: Failed to read artifact descriptor for com.zenjava:javafx-maven-plugin:jar:8.1.2
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-release-plugin/2.3.2/maven-release-plugin-2.3.2.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-release-plugin:2.3.2: Plugin org.apache.maven.plugins:maven-release-plugin:2.3.2 or one of its …Run Code Online (Sandbox Code Playgroud) Javadoc ReadOnlyProperty.getBean()表示:
对象getBean()
返回包含此属性的对象。如果此属性未包含在Object中,则返回null。
我注意到,在许多节点中,大多数(如果不是全部)属性都被定义getBean()为覆盖该方法。当然,考虑getBean()到Javadoc中对Java语言的描述,这样做非常有意义。
但是,大多数人(例如您和我)可能会这样做:
ObjectProperty<MyClass> myObj = new SimpleObjectProperty<>();
Run Code Online (Sandbox Code Playgroud)
我们没有覆盖该getBean()方法,没有它,一切似乎都可以工作。那么,是否有一些我们不能通过覆盖而错过的东西getBean()?
我已经看到了Javadoc给出的许多覆盖此方法的示例。例如,来自PseudoClass Javadoc:
public boolean isMagic() {
return magic.get();
}
public BooleanProperty magicProperty() {
return magic;
}
public BooleanProperty magic =
new BooleanPropertyBase(false) {
@Override protected void invalidated() {
pseudoClassStateChanged(MAGIC_PSEUDO_CLASS. get());
}
@Override public Object getBean() {
return MyControl.this;
}
@Override public String getName() {
return "magic";
}
};
private static final PseudoClass MAGIC_PSEUDO_CLASS = PseudoClass.getPseudoClass("xyzzy");
Run Code Online (Sandbox Code Playgroud)
我们大多数人甚至都不会使用抽象基类实例化属性(而且很可能甚至不熟悉)。为什么该示例将以这种方式而不是简单地这样做:
public boolean …Run Code Online (Sandbox Code Playgroud) 我是javaFx的新手,所以请忽略我在这里的愚蠢问题我要验证(限制)用户输入3个字符(如果用户输入更多输入,则不允许或3个字符后,后者应该可见)我发现很多验证的解决方案,但它不限制最多3个字符,也不会有点混淆理解这是我的代码.
public class editController {
@FXML
private TextField countrycode;
public void add(ActionEvent event) {
String ADD=countrycode.getText();
try {
if(ADD.isEmpty()){
Alert alert=new Alert(Alert.AlertType.ERROR);
alert.setHeaderText(null);
alert.setContentText("Please Fill All DATA");
alert.showAndWait();
return;
}
FXMLLoader loader =new FXMLLoader();
loader.load(getClass().getResource("/region/newCountry.fxml").openStream());
Run Code Online (Sandbox Code Playgroud) 我有一个特殊的情况,我想向可见属性添加一个侦听器,然后在该属性不再可见时将其删除。我只希望听众触发一次然后将其删除。
即
ChangeListener<Boolean> listener= (obs, ov, nv) -> {
if(!nv){
//do my processing
node.visibleProperty().removeListener(listener); }
}
};
node.visibleProperty().addListener(listener);
Run Code Online (Sandbox Code Playgroud)
但是,它告诉我变量侦听器可能尚未初始化。如果我尝试将其设置为null,然后创建它,它会抱怨说它实际上不是最终的
这可能吗?