是否可以定義TabBar將標籤放在底部而不是頂部?JavaFx 2.0與FXML:標籤在底部而不是頂部?
0
A
回答
0
不要定義TabBar
!使用適當的佈局窗格javafx.scene.layout.BorderPane
。 查找JavaFX的2.0 API和FXML附例子:
JavaFX的2.0 API
package tabtest;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class TabTest extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
BorderPane root = new BorderPane();
Scene scene = new Scene(root, 300, 250);
TabPane tabPane = new TabPane();
Tab tab1 = new Tab("Tab 1");
tabPane.getTabs().add(tab1);
root.setBottom(tabPane);
primaryStage.setScene(scene);
primaryStage.show();
}
}
如需進一步信息看看http://download.oracle.com/javafx/2.0/layout/jfxpub-layout.htm
FXML
package fxmltest;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class FxmlTest extends Application {
public static void main(String[] args) {
Application.launch(FxmlTest.class, args);
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
Scene scene = new Scene(root, 300, 250);
stage.setScene(scene);
stage.show();
}
}
樣品.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane>
<bottom>
<TabPane>
<tabs>
<Tab text="Tab 1" />
</tabs>
</TabPane>
</bottom>
</BorderPane>
6
要設置的選項卡的使用側下面的代碼片斷:
TabPane tabPane = new TabPane();
Tab tab1 = new Tab("Tab 1");
tab1.setContent(new Label("Tab1 content"))
tabPane.getTabs().add(tab1);
tabPane.setSide(Side.BOTTOM)
現在含量標籤上方。
此外,作爲全FXML例如:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.collections.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.web.*?>
<BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="example.MainViewController">
<bottom>
<HBox>
<children>
<Button fx:id="btnNewTab" mnemonicParsing="false" text="Add New Tab" onAction="#btnNewTabAction" />
</children>
</HBox>
</bottom>
<center>
<TabPane fx:id="tabPane" side="BOTTOM">
<tabs>
<Tab text="Untitled Tab 1">
<content>
<AnchorPane id="Content">
<Label>Content 1</Label>
</AnchorPane>
</content>
</Tab>
<Tab text="Untitled Tab 2">
<content>
<AnchorPane id="Content">
<Label>Content 2</Label>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
</center>
<top>
<Label text="TabPane Example" />
</top>
</BorderPane>
主類:
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();
}
}
}
而且控制器:
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);
}
}
,你可以看到的例子,FXML是Java類的xml表示。如果類有一個屬性方(getSide,setSide),那麼類在fxml中有一個屬性方。所以你可以閱讀api文檔來找出哪些屬性在fxml中可用。
希望這會有所幫助。
+0
你對我的回答絕對正確,謝謝!您能否提供一個解決FXML問題的適當示例? – pmoule
相關問題
- 1. 如何顯示標籤底部而不是頂部?
- 2. 記事本++標籤欄的底部而不是頂部?
- 3. 頂部垂直xtick標籤,而不是底部
- 4. 如何在頂部而不是底部
- 5. Android TabWidget TabStrip頂部而不是底部
- 6. php pchart 2.0 x軸橫座標位置(底部而不是頂部)
- 7. 動畫從底部到頂部而不是從頂部到底部的高度
- 8. 底部帶有mapview的標籤頂部
- 9. 頂部和底部的標籤欄
- 10. matplotlib colorbar交替頂部底部標籤
- 11. Drupal驗證碼顯示在頂部而不是在底部?
- 12. 腳本在div的底部被觸發而不是頂部
- 13. CSS如何在底部而不是頂部縮放
- 14. 工具欄出現在頂部而不是底部
- 15. 在頁面底部而不是頂部打印錯誤?
- 16. 導航欄突然在頂部而不是底部HTML
- 17. 將jBar定位在頁面底部而不是頂部
- 18. Display System.Windows.Forms.DataGridView new在頂部而不是底部記錄行?
- 19. 對齊一個盒子,在底部而不是頂部
- 20. 底部/頂部對齊JavaFX文本內容(標籤/文本區域)
- 21. 浮動標籤底部工作,但頂部不
- 22. jquery放在頂部,而不是光標
- 23. 獲取UITableView從底部/捕捉到底部滾動,而不是頂部
- 24. 我的標題中的文本應該是頂部而不是底部
- 25. 在標籤欄頂部顯示視圖而不是在
- 26. Android中的頂部標籤,底部標籤和動作條標籤
- 27. 如何從頂部到底部減少元素的高度,而不是從默認的底部到頂部?
- 28. 帶有CSS的條形圖,如何從底部到頂部填充,而不是從頂部到底部?
- 29. 頂部div出現在底部和底部到頂部
- 30. 對齊兩個標籤的底部和頂部在垂直UIStackView
哇。謝謝,但我正在使用fxml。這可以通過fxml完成嗎? –
我不是FXML的專家,但[this](http://download.oracle.com/javafx/2.0/fxml_get_started/jfxpub-fxml_get_started.htm)教程可能會給出答案。 – pmoule
謝謝。完美的作品 –