问题描述
我正在尝试将具有ImageView子项的TilePane添加到JavaFX中的场景.目前,我的FXML正在加载一个空的TilePane.
I'm trying to add a TilePane with ImageView children to a scene in JavaFX. Currently, my FXML is loading an empty TilePane.
我制作TilePane的当前FXML行是
The current FXML line that i have making the TilePane is
<TilePane id="MapPane" fx:id="mapPane" layoutX="3.0" layoutY="0.0" prefColumns="9" prefHeight="560.0" prefTileHeight="112.0" prefTileWidth="112.0" prefWidth="1277.0" visible="true"\>
其中mapPane是.java文件中变量的名称
where mapPane is the name of the variable in my .java file
控制器: /* *要更改此模板,请选择工具" |工具".范本 *并在编辑器中打开模板. */包screens.gameScreen;
controller: /* * To change this template, choose Tools | Templates * and open the template in the editor. */package screens.gameScreen;
import screens.*;
import mule.*;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.layout.*;
import java.awt.MouseInfo;
import java.awt.Point;
import com.sun.glass.ui.Robot;
/**
* FXML Controller class
*
* @author Stephen
*/
public class GameScreenController implements Initializable, ControlledScreen {
Robot robot = com.sun.glass.ui.Application.GetApplication().createRobot();
ScreenManager screenManager;
TileEngine tileEngine = new TileEngine();
@FXML
TilePane mapPane = tileEngine.createRandomMap(true);;
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
}
@Override
public void setScreenParent(ScreenManager screen) {
screenManager = screen;
}
@FXML
private void goToMain(ActionEvent event) {
screenManager.setScreen(mule.MULE.mainMenuScreenID);
}
}
推荐答案
,您可以使用 SceneBuilder 用于创建FXML.这样可以轻松解决您的问题.
you can use SceneBuilder for create FXML. This can easily solve your problem.
这篇关于将在.java文件中实例化的TilePane添加到FXML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!