是否可以定义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
谢谢。完美的作品 –