1
我正在使用eclipse和場景生成器。javafx - 如何在運行時將fxml元素添加到選項卡面板中?
我想在運行時添加elemnts到選項卡。 每個元素是fxml文件(其中包含按鈕,tableView,文本框...)。
該選項卡不包含固定數量的元素。
我需要你的幫助,因爲我無法找到一種方法如何做到這一點? 如何添加任何元素到標籤? 如何將描述元素(fxml)添加到選項卡中?
感謝
我正在使用eclipse和場景生成器。javafx - 如何在運行時將fxml元素添加到選項卡面板中?
我想在運行時添加elemnts到選項卡。 每個元素是fxml文件(其中包含按鈕,tableView,文本框...)。
該選項卡不包含固定數量的元素。
我需要你的幫助,因爲我無法找到一種方法如何做到這一點? 如何添加任何元素到標籤? 如何將描述元素(fxml)添加到選項卡中?
感謝
我不知道我完全理解你的使用情況,但有一個看看FX:根結構:
import java.io.IOException;
import javafx.scene.layout.BorderPane;
import org.drombler.commons.fx.fxml.FXMLLoaders;
public class MyCustomtPane extends BorderPane {
public TopTestPane() throws IOException {
loadFXML();
}
private void loadFXML() throws IOException {
FXMLLoaders.loadRoot(this);
}
}
在同一封裝中增加一個MyCustomtPane .fxml文件:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<fx:root type="BorderPane" xmlns:fx="http://javafx.com/fxml">
<center>
<Label text="%label.text"/>
</center>
</fx:root>
在相同的包添加一個MyCustomtPane.properties文件:
label.text=Some text
別的地方在你的代碼,你可以使用:
...
MyCustomtPane myCustomtPane = new MyCustomtPane(); // will load the FXML as well
addToProperPlace(myCustomtPane);
注:FXMLLoaders是我寫的一個工具類。 庫是開源的,請直接從Maven的中央:
<dependency>
<groupId>org.drombler.commons</groupId>
<artifactId>drombler-commons-fx-core</artifactId>
<version>0.4</version>
</dependency>
能否請您解釋一下「添加上運行時元素標籤每一個元素都是FXML文件。」據我所知,你可以添加一個[內容](http://docs.oracle.com/javafx/2/api/javafx/scene/control/Tab.html#setContent%28javafx.scene.Node%29)在標籤中。你能解釋你在這裏想達到什麼嗎? – ItachiUchiha 2014-09-19 08:26:18