Adding a TilePane instantiated in .java files to F

2019-03-01 14:58发布

I'm trying to add a TilePane with ImageView children to a scene in JavaFX. Currently, my FXML is loading an empty TilePane.

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"\>

where mapPane is the name of the variable in my .java file

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);
}
}

标签: javafx-2 fxml
1条回答
一夜七次
2楼-- · 2019-03-01 15:40

you can use SceneBuilder for create FXML. This can easily solve your problem.

查看更多
登录 后发表回答