Javafx TabPane 无法滚动到最后一个 Tab
Javafx TabPane not able to scroll to last Tab
package com.ge.health.signaturegenerator;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TabPane.TabClosingPolicy;
import javafx.scene.control.TitledPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class Main2 extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) throws FileNotFoundException {
primaryStage.setTitle("Signature Generator");
VBox rootBox = new VBox();
Scene scene = new Scene(rootBox, 1600, 950, Color.TRANSPARENT);
scene.getStylesheets().add("NewFile.css");
rootBox.setStyle("-fx-background-color: #A9A9A9;");
MenuBar bar = new MenuBar();
bar.setStyle("-fx-background-color: #A9A9A9; -fx-border-color: black; -fx-border-width: 0.5;");
Menu fileMenu = new Menu("File");
fileMenu.getItems().add(new MenuItem("Load"));
bar.getMenus().add(fileMenu);
bar.getMenus().add(new Menu("Help"));
rootBox.getChildren().add(bar);
GridPane headerPane = new GridPane();
headerPane.setPadding(new Insets(5));
headerPane.setHgap(5);
headerPane.setVgap(5);
ColumnConstraints column1 = new ColumnConstraints(200);
ColumnConstraints column2 = new ColumnConstraints(200);
ColumnConstraints column3 = new ColumnConstraints(200);
ColumnConstraints column4 = new ColumnConstraints(200);
headerPane.getColumnConstraints().addAll(column1, column2, column3, column4);
Label ageLabel = new Label("Age : 68");
Label heightLabel = new Label("Height : 180 cm");
Label widthLabel = new Label("width : 75 cm");
Button button1 = new Button("Generate Atlas");
headerPane.add(ageLabel, 0, 0);
headerPane.add(heightLabel, 1, 0);
headerPane.add(widthLabel, 2, 0);
headerPane.add(button1, 3, 0);
headerPane.setStyle("-fx-background-color: #A9A9A9;");
rootBox.getChildren().add(headerPane);
TabPane tabPane = new TabPane();
tabPane.setSide(Side.LEFT);
tabPane.setTabMinHeight(300);
tabPane.setTabMaxWidth(15);
tabPane.setStyle("-fx-border-color: black; -fx-border-width: 1; -fx-open-tab-animation: grow;");
tabPane.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE);
for (int i = 0; i < 15; i++) {
Tab tab = new Tab();
Label l = new Label("Tab " + i + "Tab " + i + "Tab " + i + "Tab " + i);
l.setStyle("-fx-rotate: 90;");
l.setMinSize(200, 40);
tab.setGraphic(l);
tab.getGraphic().autosize();
tab.setStyle("-fx-background-color: #A9A9A9;");
tab.setClosable(false);
ImageView imView = null;
int j = i % 2;
if (j == 0) {
imView = new ImageView(new Image(
new FileInputStream(new File("C:/Users/502655636/Pictures/2016-08-19_17h23_08.png"))));
} else {
imView = new ImageView(new Image(
new FileInputStream(new File("C:/Users/502655636/Pictures/2016-08-19_17h07_40.png"))));
}
GridPane grid = new GridPane();
VBox vbox = new VBox(imView);
grid.add(vbox, 0, 0, 1, 6);
grid.setStyle("-fx-background-color: #FFFFFF;");
TitledPane[] titledPaneTab = new TitledPane[6];
for (int k = 0; k < 6; k++) {
GridPane buttonsGrid = new GridPane();
buttonsGrid.setPadding(new Insets(5));
buttonsGrid.setHgap(5);
buttonsGrid.setVgap(5);
ColumnConstraints buttonColumn1 = new ColumnConstraints(100);
buttonsGrid.getColumnConstraints().addAll(buttonColumn1);
buttonsGrid.add(new HBox(), 0, 0);
Label read = new Label("Read pos. : ");
read.setMinWidth(100);
Label selected = new Label("Selected pos. : ");
selected.setMinWidth(100);
HBox box1 = new HBox(100, read, selected);
buttonsGrid.add(box1, 0, 1);
Button mark = new Button("Mark");
mark.setMinWidth(100);
Button delete = new Button("Delete");
delete.setMinWidth(100);
Button reset = new Button("Reset");
reset.setMinWidth(100);
HBox box2 = new HBox(10, mark, delete, reset);
buttonsGrid.add(box2, 0, 2);
buttonsGrid.setStyle("-fx-background-color: #A9A9A9;");
TitledPane ggg = new TitledPane("Parts " + i, buttonsGrid);
ggg.setCollapsible(false);
ggg.setMinWidth(400);
ggg.setStyle("-fx-content-display: top; -fx-border-insets: 20 15 15 15; -fx-background-color: #FFFFFF; -fx-border-color: black; -fx-border-width: 1;");
titledPaneTab[k] = ggg;
}
VBox box2 = new VBox(titledPaneTab);
grid.addColumn(1, box2);
tab.setContent(grid);
tabPane.getTabs().add(tab);
}
// bind to take available space
BorderPane borderPane = new BorderPane();
borderPane.prefHeightProperty().bind(scene.heightProperty());
borderPane.prefWidthProperty().bind(scene.widthProperty());
borderPane.setCenter(tabPane);
rootBox.getChildren().add(borderPane);
primaryStage.setScene(scene);
primaryStage.show();
}
}
你好
我正在尝试开发一个 javafx 小应用程序。
我遇到了 javafx TabPane 问题。如果选项卡多于舞台无法显示,我将无法滚动到页面底部。
任何人的想法。
我用这个 css 也
.tab-pane *.tab-header-background {
-fx-background-color: #000000;
}
.tab-pane *.tab:selected {
-fx-color: #FFFFFF;
}
结果如下
出现箭头。
问题是我在页眉中有 30 个选项卡,但我无法滚动到最后一个。即使我 select 它通过箭头,它也不会出现
谢谢
You can put tabpane into scrollpane – GlacialMan Aug 31 at 23:03
谢谢 GlacialMan
package com.ge.health.signaturegenerator;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TabPane.TabClosingPolicy;
import javafx.scene.control.TitledPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class Main2 extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) throws FileNotFoundException {
primaryStage.setTitle("Signature Generator");
VBox rootBox = new VBox();
Scene scene = new Scene(rootBox, 1600, 950, Color.TRANSPARENT);
scene.getStylesheets().add("NewFile.css");
rootBox.setStyle("-fx-background-color: #A9A9A9;");
MenuBar bar = new MenuBar();
bar.setStyle("-fx-background-color: #A9A9A9; -fx-border-color: black; -fx-border-width: 0.5;");
Menu fileMenu = new Menu("File");
fileMenu.getItems().add(new MenuItem("Load"));
bar.getMenus().add(fileMenu);
bar.getMenus().add(new Menu("Help"));
rootBox.getChildren().add(bar);
GridPane headerPane = new GridPane();
headerPane.setPadding(new Insets(5));
headerPane.setHgap(5);
headerPane.setVgap(5);
ColumnConstraints column1 = new ColumnConstraints(200);
ColumnConstraints column2 = new ColumnConstraints(200);
ColumnConstraints column3 = new ColumnConstraints(200);
ColumnConstraints column4 = new ColumnConstraints(200);
headerPane.getColumnConstraints().addAll(column1, column2, column3, column4);
Label ageLabel = new Label("Age : 68");
Label heightLabel = new Label("Height : 180 cm");
Label widthLabel = new Label("width : 75 cm");
Button button1 = new Button("Generate Atlas");
headerPane.add(ageLabel, 0, 0);
headerPane.add(heightLabel, 1, 0);
headerPane.add(widthLabel, 2, 0);
headerPane.add(button1, 3, 0);
headerPane.setStyle("-fx-background-color: #A9A9A9;");
rootBox.getChildren().add(headerPane);
TabPane tabPane = new TabPane();
tabPane.setSide(Side.LEFT);
tabPane.setTabMinHeight(300);
tabPane.setTabMaxWidth(15);
tabPane.setStyle("-fx-border-color: black; -fx-border-width: 1; -fx-open-tab-animation: grow;");
tabPane.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE);
for (int i = 0; i < 15; i++) {
Tab tab = new Tab();
Label l = new Label("Tab " + i + "Tab " + i + "Tab " + i + "Tab " + i);
l.setStyle("-fx-rotate: 90;");
l.setMinSize(200, 40);
tab.setGraphic(l);
tab.getGraphic().autosize();
tab.setStyle("-fx-background-color: #A9A9A9;");
tab.setClosable(false);
ImageView imView = null;
int j = i % 2;
if (j == 0) {
imView = new ImageView(new Image(
new FileInputStream(new File("C:/Users/502655636/Pictures/2016-08-19_17h23_08.png"))));
} else {
imView = new ImageView(new Image(
new FileInputStream(new File("C:/Users/502655636/Pictures/2016-08-19_17h07_40.png"))));
}
GridPane grid = new GridPane();
VBox vbox = new VBox(imView);
grid.add(vbox, 0, 0, 1, 6);
grid.setStyle("-fx-background-color: #FFFFFF;");
TitledPane[] titledPaneTab = new TitledPane[6];
for (int k = 0; k < 6; k++) {
GridPane buttonsGrid = new GridPane();
buttonsGrid.setPadding(new Insets(5));
buttonsGrid.setHgap(5);
buttonsGrid.setVgap(5);
ColumnConstraints buttonColumn1 = new ColumnConstraints(100);
buttonsGrid.getColumnConstraints().addAll(buttonColumn1);
buttonsGrid.add(new HBox(), 0, 0);
Label read = new Label("Read pos. : ");
read.setMinWidth(100);
Label selected = new Label("Selected pos. : ");
selected.setMinWidth(100);
HBox box1 = new HBox(100, read, selected);
buttonsGrid.add(box1, 0, 1);
Button mark = new Button("Mark");
mark.setMinWidth(100);
Button delete = new Button("Delete");
delete.setMinWidth(100);
Button reset = new Button("Reset");
reset.setMinWidth(100);
HBox box2 = new HBox(10, mark, delete, reset);
buttonsGrid.add(box2, 0, 2);
buttonsGrid.setStyle("-fx-background-color: #A9A9A9;");
TitledPane ggg = new TitledPane("Parts " + i, buttonsGrid);
ggg.setCollapsible(false);
ggg.setMinWidth(400);
ggg.setStyle("-fx-content-display: top; -fx-border-insets: 20 15 15 15; -fx-background-color: #FFFFFF; -fx-border-color: black; -fx-border-width: 1;");
titledPaneTab[k] = ggg;
}
VBox box2 = new VBox(titledPaneTab);
grid.addColumn(1, box2);
tab.setContent(grid);
tabPane.getTabs().add(tab);
}
// bind to take available space
BorderPane borderPane = new BorderPane();
borderPane.prefHeightProperty().bind(scene.heightProperty());
borderPane.prefWidthProperty().bind(scene.widthProperty());
borderPane.setCenter(tabPane);
rootBox.getChildren().add(borderPane);
primaryStage.setScene(scene);
primaryStage.show();
}
}
你好
我正在尝试开发一个 javafx 小应用程序。
我遇到了 javafx TabPane 问题。如果选项卡多于舞台无法显示,我将无法滚动到页面底部。
任何人的想法。
我用这个 css 也
.tab-pane *.tab-header-background {
-fx-background-color: #000000;
}
.tab-pane *.tab:selected {
-fx-color: #FFFFFF;
}
结果如下
出现箭头。
问题是我在页眉中有 30 个选项卡,但我无法滚动到最后一个。即使我 select 它通过箭头,它也不会出现
谢谢
You can put tabpane into scrollpane – GlacialMan Aug 31 at 23:03
谢谢 GlacialMan