把FXML文件转换为java_在fxml文件之间切换

我已经在swing组件内使用jfxPanel创建了一个应用程序。我面临的问题是我无法更改fxml文件。当单击fxml的按钮时,我要处理该fxml并在那里加载另一个fxml文件。这是我到目前为止所做的

public class NonResponsiveButtons extends JFrame {

NonResponsiveButtons nrb;

BottomPanelIncomingController bpic;

JPanel panel;

JPanel bPanel;

private int applicationWidth_600 = 600;

private int applicationHeight_600 = 600;

private int upperPanelHeight_535 = 535;

private int bottomPanelHeight_65 = (applicationHeight_600-upperPanelHeight_535);

public static void main(String[] args) {

new NonResponsiveButtons();

}

public NonResponsiveButtons(){

final JFXPanel fxPanel = new JFXPanel();

SwingUtilities.invokeLater(new Runnable() {

@Override

public void run() {

// TODO Auto-generated method stub

try{

new JFXPanel();

add(getJPanel(), BorderLayout.CENTER);

add(getJBottomPanel(), BorderLayout.PAGE_END);

bPanel.add(fxPanel, BorderLayout.CENTER);

Platform.runLater((new Runnable() {

@Override

public void run() {

// TODO Auto-generated method stub

initFX(fxPanel);

}

})) ;

}

catch(Exception e){

System.out.println("Error in swing utilities thread :" + e.getMessage());

}

}

});

this.setSize(applicationWidth_600, applicationHeight_600);

setLocationRelativeTo(null);

BorderLayout borderLayout = new BorderLayout();

setLayout(borderLayout);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

}

private void initFX(JFXPanel jfxPanel) {

try {

FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("fxmlDesign.fxml"));

Parent root = (Parent) fxmlLoader.load();

Scene scene = new Scene(root, 600, 65);

jfxPanel.setScene(scene);

fxmlLoader.getController();

bpic = new BottomPanelIncomingController();

bpic.setNonResoinsiveButtons(this);

} catch (IOException exc) {

exc.printStackTrace();

System.exit(1);

}

}

public void loadSecondFxml(){

System.out.println("loading second fxml");

}

private JPanel getJPanel(){

if(panel == null){

panel = new JPanel();

panel.setSize(applicationWidth_600,upperPanelHeight_535);

panel.setBackground(Color.gray);

}

return panel;

}

private JPanel getJBottomPanel(){

if(bPanel == null){

bPanel = new JPanel();

bPanel.setSize(applicationWidth_600, bottomPanelHeight_65);

bPanel.setBackground(new Color(8, 16, 19));

}

return bPanel;

}

}

BottomPanelIncommingController类。fxml控制器

public class BottomPanelIncomingController implements Initializable {

NonResponsiveButtons nrb;

@Override

public void initialize(URL arg0, ResourceBundle arg1) {

// TODO Auto-generated method stub

System.out.println("HEllo");

}

public void setNonResoinsiveButtons(NonResponsiveButtons nrb){

this.nrb = nrb;

}

@FXML

public void callAccepted(ActionEvent event){

System.out.println("From controller");

nrb.loadSecondFxml();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值