How to get data from Tab in Tabpane JavaFX


I want get data from Tab in Tabpane JavaFX

I have 2 Tab in Tabpane, And each Tab I have a TextArea, I want click Button will get data from 2 tab

<a href="https://i.stack.imgur.com/p6UEt.jpg" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/p6UEt.jpg" data-original="https://i.stack.imgur.com/p6UEt.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

<a href="https://i.stack.imgur.com/gr7M9.jpg" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/gr7M9.jpg" data-original="https://i.stack.imgur.com/gr7M9.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Here's my code:

btnThem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { try { i++; FXMLLoader fxmlLoader = new FXMLLoader( getClass().getResource("/fxml/tab.fxml")); Parent parent = (Parent) fxmlLoader.load(); Tab tab = new Tab("Điểm " + i); tab.setContent(parent); tab.setClosable(true); tabPane.getTabs().add(tab); controllerTab = (ControllerTab) fxmlLoader.getController(); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } });


Your question is ambiguous but it seems you want to get data from each textArea in tab.To do this you should get nodes (children) from each tab and by using lookup() we confirm and we parse node to textArea.I tried to figure your scene and made this example to help you :

public class example extends Application { TextArea textArea = new TextArea(); TextArea textArea1 = new TextArea(); Button button = new Button("button"); @Override public void start(Stage primaryStage) { Tab tab1 = new Tab("tab1"); Tab tab2 = new Tab("tab2"); tab1.setContent(textArea); tab2.setContent(textArea1); TabPane pane = new TabPane(); pane.getTabs().addAll(tab1, tab2); Node node1 = tab1.getContent(); Node node2 = tab2.getContent(); button.setOnAction((ActionEvent event) -> { if (node1.lookup("TextArea") != null && node2.lookup("TextArea") != null) { TextArea area1 = (TextArea) node1.lookup("TextArea"); TextArea area2 = (TextArea) node2.lookup("TextArea"); System.out.println(area1.getText() + " " + area2.getText()); } }); VBox root = new VBox(); root.setAlignment(Pos.TOP_RIGHT); root.getChildren().add(pane); root.getChildren().add(button); Scene scene = new Scene(root, 300, 250); primaryStage.setTitle("Hello World!"); primaryStage.setScene(scene); primaryStage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }

And you can see the result :

<a href="https://i.stack.imgur.com/EzW84.png" rel="nofollow"><img alt="Data in tab1" class="b-lazy" data-src="https://i.stack.imgur.com/EzW84.png" data-original="https://i.stack.imgur.com/EzW84.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

<a href="https://i.stack.imgur.com/TJzTf.png" rel="nofollow"><img alt="Data in tab2" class="b-lazy" data-src="https://i.stack.imgur.com/TJzTf.png" data-original="https://i.stack.imgur.com/TJzTf.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

<a href="https://i.stack.imgur.com/ckSuI.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/ckSuI.png" data-original="https://i.stack.imgur.com/ckSuI.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Hello ,tab1 Hello ,tab2 Deleting directory C:\Users\Electron\Documents\NetBeansProjects\Buttono\dist\run341573612 jfxsa-run: BUILD SUCCESSFUL (total time: 22 seconds)


  • Android Maps within TabHost. getTabHost() return error
  • javafx Tableview not showing data from database
  • Empty OsmDroid Map? Where to custom the new map?
  • want to draw a line between any two location in android
  • Update JavaFX scene graph from a Thread
  • Change subtype in Hibernate Inheritance
  • Retrofit 2 error: NetworkOnMainThreadException
  • problem with classes not found during PlayPlugin.enhance
  • Runtime error in UVA Online Judge [closed]
  • 3.0.0.M1: SSL - Invalid keystore format
  • How to handle empty space in url when downloading image from web?
  • Problem with rejecting incoming call
  • powershell Get-Counter -ComputerName parameter on Windows 7
  • Xamarin MonoAndroid Azure mobile service InsertAsync
  • Suqueries in select clause with JPA
  • Exception creating JSON with LINQ
  • How to copy styled text in JTextPane
  • Why does it draw lines in the wrong place?
  • Can I read an iPhone beacon with Windows.Devices.Bluetooth.Advertisement.BluetoothLEManufacturerData
  • TFS 2015 - Waiting for an agent to be requested
  • URLConnection doesn't work since API 10 and higher?
  • 550 Access denied - Invalid HELO name
  • Problems installing Yesod for Haskell
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • Converting a WriteableBitmap image ToArray in UWP
  • How to test if a URL from an Eclipse bundle is a directory?
  • Reading JSON from a file using C++ REST SDK (Casablanca)
  • Ajax Loaded meta Tags
  • Lost migrations and Azure database is now out of sync
  • Xamarin Forms - UWP Fonts
  • Why value captured by reference in lambda is broken? [duplicate]
  • Launch Runnable Jar from Web Start
  • Volley JsonObjectRequest send headers in GET Request
  • How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
  • javascript inside java/jsp code
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Arrays break string types in Julia
  • Android Studio and gradle
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • How can i traverse a binary tree from right to left in java?