6
A
回答
13
具有對Tab
小號iconed Button
S:
的Tab
的setGraphic
方法可用於添加任何Node
上Tab
顯示。可以添加Button
,因爲它是Node
。
在此之後,一個功能齊全的按鈕存在,但它不顯示任何圖標。 Button
也有方法,它的工作原理相同,因此可以添加ImageView
以在Button
上顯示Image
。
要具有控制Button
S於的標籤區域的右上角:
這些按鈕可以放置上TabPane
,而非TabPane
內部。爲此,您可以使用AnchorPane
將Button
定位到右上角。
例子:
public class ButtonedTabPane extends Application {
@Override
public void start(Stage primaryStage) {
BorderPane root = new BorderPane();
TabPane tabPane = new TabPane();
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
// HBox of control buttons
HBox hbox = new HBox();
hbox.getChildren().addAll(createTabButton("min.png"), createTabButton("max.png"));
// Anchor the controls
AnchorPane anchor = new AnchorPane();
anchor.getChildren().addAll(tabPane, hbox);
AnchorPane.setTopAnchor(hbox, 3.0);
AnchorPane.setRightAnchor(hbox, 5.0);
AnchorPane.setTopAnchor(tabPane, 1.0);
AnchorPane.setRightAnchor(tabPane, 1.0);
AnchorPane.setLeftAnchor(tabPane, 1.0);
AnchorPane.setBottomAnchor(tabPane, 1.0);
// Create some tabs
Tab tab = new Tab("Files");
tab.setGraphic(createTabButton("files.png"));
((Button) tab.getGraphic()).setOnAction(e -> System.out.println("I'll show the list of files!"));
tabPane.getTabs().add(tab);
tab = new Tab("Network");
tab.setGraphic(createTabButton("network.png"));
((Button) tab.getGraphic()).setOnAction(e -> System.out.println("I'll show the network!"));
tabPane.getTabs().add(tab);
root.setCenter(anchor);
Scene scene = new Scene(root, 400, 400);
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
private Button createTabButton(String iconName) {
Button button = new Button();
ImageView imageView = new ImageView(new Image(getClass().getResource(iconName).toExternalForm(),
16, 16, false, true));
button.setGraphic(imageView);
button.getStyleClass().add("tab-button");
return button;
}
public static void main(String[] args) {
launch(args);
}
}
唯一剩下刪除從Button
S中的默認背景和邊框。這可以通過將以下CSS選擇器插入到CSS樣式表中來完成。
的style.css
.tab-button {
-fx-border-width: 0;
-fx-background-radius: 0;
-fx-background-color: transparent;
-fx-content-display: graphic-only;
}
.tab-button:hover {
-fx-background-color: white;
}
結果:
相關問題
- 1. 將按鈕添加到文本區javafx
- 2. 將製表符添加到頁面
- 3. Jquery製表符加載更多按鈕
- 4. 使用其內容添加製表符到製表符
- 5. 從tab中添加製表符到製表符
- 6. 添加viewpager爲製表符
- 7. natvis - 添加製表符到輸出
- 8. 如何添加製表符到UINavigationController
- 9. 將內容添加到製表符/下拉列表
- 10. 在Vim中複製沒有換行符和製表符的區域
- 11. JavaFX:使用垂直製表符和水平製表符標籤格式化製表符欄
- 12. 將定製按鈕添加到TinyMCE
- 13. Jquery製表符的Next&Back按鈕
- 14. jQuery添加和限制表單域
- 15. ps -ef | wc -l將製表符添加到該行的前面
- 16. 將1的列添加到製表符分隔的文件
- 17. 如何將列添加到txt製表符分隔文件
- 18. 使用Javascript將製表符添加到textarea
- 19. 將標題添加到製表符分隔文件
- 20. 將CSS類添加到表單按鈕
- 21. 將按鈕添加到列表活動
- 22. Codeigniter將Glyphicon添加到表單按鈕
- 23. 將按鈕添加到asp:表
- 24. 將按鈕添加到圖表 - svg
- 25. 將按鈕添加到excel工作表
- 26. 將按鈕添加到表格腳註
- 27. 在numberpad中添加邊框到按鈕上的按鈕並在空白區域添加+符號
- 28. JavaFX TabPane禁用製表符切換鍵
- 29. 如何批量添加製表符到字符串
- 30. 如何將字符串和int添加到按鈕中的列表框中
TNX該做的工作 – JimmyD