Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To set the side of the tabs use following snippet:</p> <pre><code>TabPane tabPane = new TabPane(); Tab tab1 = new Tab("Tab 1"); tab1.setContent(new Label("Tab1 content")) tabPane.getTabs().add(tab1); tabPane.setSide(Side.BOTTOM) </code></pre> <p>Now the content is above the tabs.</p> <p>Also as full FXML example:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;?import java.lang.*?&gt; &lt;?import java.util.*?&gt; &lt;?import javafx.collections.*?&gt; &lt;?import javafx.scene.control.*?&gt; &lt;?import javafx.scene.effect.*?&gt; &lt;?import javafx.scene.image.*?&gt; &lt;?import javafx.scene.layout.*?&gt; &lt;?import javafx.scene.paint.*?&gt; &lt;?import javafx.scene.shape.*?&gt; &lt;?import javafx.scene.text.*?&gt; &lt;?import javafx.scene.web.*?&gt; &lt;BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="example.MainViewController"&gt; &lt;bottom&gt; &lt;HBox&gt; &lt;children&gt; &lt;Button fx:id="btnNewTab" mnemonicParsing="false" text="Add New Tab" onAction="#btnNewTabAction" /&gt; &lt;/children&gt; &lt;/HBox&gt; &lt;/bottom&gt; &lt;center&gt; &lt;TabPane fx:id="tabPane" side="BOTTOM"&gt; &lt;tabs&gt; &lt;Tab text="Untitled Tab 1"&gt; &lt;content&gt; &lt;AnchorPane id="Content"&gt; &lt;Label&gt;Content 1&lt;/Label&gt; &lt;/AnchorPane&gt; &lt;/content&gt; &lt;/Tab&gt; &lt;Tab text="Untitled Tab 2"&gt; &lt;content&gt; &lt;AnchorPane id="Content"&gt; &lt;Label&gt;Content 2&lt;/Label&gt; &lt;/AnchorPane&gt; &lt;/content&gt; &lt;/Tab&gt; &lt;/tabs&gt; &lt;/TabPane&gt; &lt;/center&gt; &lt;top&gt; &lt;Label text="TabPane Example" /&gt; &lt;/top&gt; &lt;/BorderPane&gt; </code></pre> <p>The main class:</p> <pre><code>package example; import java.io.File; import java.io.IOException; import java.net.URL; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.fxml.JavaFXBuilderFactory; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; public class ExampleMain extends Application { /** * @param args */ public static void main(String[] args) { Application.launch(ExampleMain.class, args); } @Override public void start(Stage primaryStage) throws Exception { URL location = ExampleMain.class.getResource("MainView.fxml"); FXMLLoader fxmlLoader = new FXMLLoader(); fxmlLoader.setLocation(location); fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory()); try { Parent root = (Parent) fxmlLoader.load(location.openStream()); // in case you need access to the controller MainViewController mainViewController = fxmlLoader.getController(); primaryStage.setScene(new Scene(root, 1024, 768)); Scene s = primaryStage.getScene(); s.setRoot(root); primaryStage.sizeToScene(); primaryStage.show(); } catch (IOException e) { e.printStackTrace(); } } } </code></pre> <p>And the controller:</p> <pre><code>package example; import javafx.fxml.FXML; import javafx.scene.control.Label; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; public class MainViewController { private static int counter = 0; @FXML private TabPane tabPane; @FXML public void btnNewTabAction() { Tab tab = new Tab(); tab.setText("new Tab " + ++counter); tab.setContent(new Label("Content of new tab " + counter)); tabPane.getTabs().add(tab); } } </code></pre> <p>as you can see in the example, fxml is an xml representation of the Java classes. If the class has an property side (getSide, setSide) then the class has in fxml an attribute side. So you can read the api documentation to find out which attributes are available in fxml as well.</p> <p>Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload