我想做一些事情,在控制器的initialize()方法完成后,但在场景show之前.在场景显示之前是否会调用任何方法?我想在方法中加入一些代码.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("sample.fxml"));
AnchorPane pane = loader.load();
Scene gameScene = new Scene(pane);
//I load a secne above,the I will get the controller,set some properties,then,use the properties to read a file before the secene show.
GameUIController controller = loader.getController();
controller.setGameFileLoacation("game1.txt");//I set a property here.I want to use it to read game file,and load game,set some necessary UI.
primaryStage.setScene(gameScene);//this tow statement will show the scene.
primaryStage.show();
Run Code Online (Sandbox Code Playgroud)
我无法将代码放入initialize()方法,因为它会在fxml文件加载时调用(当我还没有得到控制器时).那么,我该怎么办?
非常感谢 !
我是JavaFX的新手,我正在尝试创建类似于下图的通知徽章. 
它将被用作通知计数,我希望将它放在JavaFX按钮的角落.我的问题是我找不到支持它的原生解决方案.有人可以推荐一种方法吗?
谢谢
我为按钮设置了工具提示,但是它看起来太小(字体大小),我怎么可以将其放大?我试过了myTooltip.setFont(new Font(20)),但是为什么不起作用,为什么?如何使字体变大?谢谢大家!
public void startApp(){
primaryStage.show();
new Thread(new Runnable(){
public void run(){
Thread.sleep(20000);//2 seconds
//do something.........
System.out.println("all things done");
}
}).run();
}
Run Code Online (Sandbox Code Playgroud)
我认为primaryStage将首先显示.但事实上,在新线程完成之后(在打印完所有事情之后),primaryStage始终显示.如果我删除'Thread.sleep(20000)',那么在所有事情完成之后,primaryStage也会被删除.为什么?我错了吗?先谢谢大家!
使用此代码我初始化组合框
@FXML
private ComboBox category;
Run Code Online (Sandbox Code Playgroud)
并使用以下方法获取价
String Category = category.getValue().toString();
Run Code Online (Sandbox Code Playgroud)
并将值插入mysql数据库.现在,在类别组合框中插入下一个值之前,我需要将数据库中的值导入到组合框中的下拉列表中,并且值应该显示在组合框中.
我需要在大学中为我的项目创建一个生成类似隧道的曲线.我在Internet上找到了一些代码,允许我拖动曲线的控制点(附加到Anchor对象).
但是,我想通过按箭头键("向上"和"向下")来改变控制点Ylocation是可能的,并且它根本不起作用.我自己一直试图绝望地解决这个问题,但我找不到出路.
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
import javafx.event.EventHandler;
import javafx.scene.*;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.stage.Stage;
/** Example of how a cubic curve works, drag the anchors around to change the curve. */
public class testsdfasdf extends Application {
public static void main(String[] args) throws Exception { launch(args); }
@Override public void start(Stage primaryStage) throws Exception {
QuadCurve curve = createStartingCurve();
final BorderPane root = new BorderPane();
Scene scene = new Scene(root, 1000, 1000); …Run Code Online (Sandbox Code Playgroud) 我有一个父控制器,其中包含一个按钮.当我点击按钮时,它打开新窗口并将一些数据显示在表格中.我用于打开窗口的代码是
Stage stage = new Stage();
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("../layout/SearchCustomer.fxml"));
Parent parent = (Parent) fxmlLoader.load();
Scene scene = new Scene(parent);
stage.initModality(Modality.APPLICATION_MODAL);
stage.initOwner(parent.getScene().getWindow());
stage.setScene(scene);
stage.resizableProperty().setValue(false);
stage.showAndWait();
Run Code Online (Sandbox Code Playgroud)
它正确打开窗口.现在我需要的是,当我双击子窗口的表行时,它应该在父控制器文本框中设置一些值.我们如何将这个值从子控制器传递给父控制器?
我有很多具有名称a1,a2,a3,...的对象我需要将它们放入List中,因此使用它们更简单,我会以某种方式使用循环吗?
我的尝试是:
List<SomeObject> list = new LinkedList<SomeObject>();
for (int i=0; i<1000; i++){
String varName = "a"+i;
list.add((SomeObject) varName);
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下有人有建议吗?在循环内创建变量不是解决方案,因为它们是.fxml文档的一部分.或者给我一个如何用循环创建它的建议,因为它在.fxml中创建行并行添加循环新对象.
为了更容易理解.fxml文件看起来像
<SomeObject fx:id="a1" *other props* />
<SomeObject fx:id="a2" *other props* />
<SomeObject fx:id="a3" *other props* />
<SomeObject fx:id="a4" *other props* />
Run Code Online (Sandbox Code Playgroud)
非常感谢您的建议!
我有一个标签.尝试在我的CSS中为这个标签设置径向渐变.我怎么能这样做?如果我设置-fx-background-color:径向渐变(中心50%50%,半径50%,rgb(104,163,193)0%,rgb(23,56,99)100%); - 我收到错误"参数不匹配"感谢您的帮助!
如何检测何时CheckBoxTreeItem选择或未选择?
我是否使用事件处理程序或更改侦听器?我要检查什么事?是否有我可以收听的事件列表,如checkboxtreeitem.selection或其他什么?
谢谢