2015-07-21 13 views
1
package sample.GUI; 

import sample.sampleThing; 
import javafx.fxml.FXML; 
import javafx.fxml.Initializable; 
import javafx.scene.control.*; 
import javafx.scene.layout.AnchorPane; 

import java.net.URL; 
import java.util.Objects; 
import java.util.ResourceBundle; 

@SuppressWarnings("unused") 
public class Console implements Initializable { 
    public TextField messageOut = new TextField(); 
    public TextArea consoleOutput = new TextArea(); 
    public AnchorPane TabAnchorPane = new AnchorPane(messageOut, consoleOutput); 
    public Tab tab = new Tab("Tab", TabAnchorPane); 

    @FXML 
    private TabPane tabPane; 
    SingleSelectionModel<Tab> selectionModel = tabPane.getSelectionModel(); 

    String string1, string2; 

    public Console() { 
     super(); 
    } 

    public Console(String str, String str2) { 
     super(); 
     this.string1 = str; 
     this.string2 = str2; 
    } 

    public void newTab(String str){ 
     Tab ntab = tab; 
     tab.setText(str); 
     tabPane.getTabs().add(ntab); 
    } 

    public void initialize(URL url, ResourceBundle rb){ 
     Tab tab1 = tab, tab2 = tab; 
     tab1.setText(string1); 
     tab2.setText(string2); 
     tabPane.getTabs().addAll(tab1, tab2); 
    } 

    public void clear() { 
     Tab tmptb = selectionModel.getSelectedItem(); 

     //GUIUtils.runSafe(tmptb.consoleOutput::clear); 
    } 

代碼的JavaFX獲得元素從我的GUI類(改名事情保密有關我的項目) 我需要什麼是獲得consoleOutput &每片 & messageOut具體從標籤

node[] arr = getTab.getContent.getNodeArray //or something like that 
for(node nd : arr) { 
    if (nd == consoleOutput || nd == messageOut) 
     //do much stuff 
} 

幫助我可以提供更多的信息,但我不知道我應該提供什麼 GUIUtils.runSafe只是一個可運行的從https://codereview.stackexchange.com/questions/52197/console-component-in-javafx 實際上這個代碼的一點是基於他有什麼...

+0

的標籤具有Tab.getContent();它返回一個節點 – Elltz

回答

1

Tab鍵節點,節點到家長,家長通常有孩子:

((Parent) tab.getContent()). 
    getChildrenUnmodifiable();