kat*_*to2 5 javafx scrollpane autoscroll
我有一个带有各种TitledPane的scrollPane,每个TitledPane都有各种文本字段作为子项.当我使用Tab键在整个文本字段中导航时,滚动窗格不会自动滚动以确保控件获得焦点可见.这是一个展示问题的程序.
import java.util.Random;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class ScrollPaneEnsureVisible extends Application {
private static final Random random = new Random();
@Override
public void start(Stage primaryStage) {
VBox root = new VBox();
ScrollPane scrollPane = new ScrollPane();
Pane content = new Pane();
scrollPane.setContent(content);
for (int i = 0; i < 3; i++) {
TitledPane pane = new TitledPane();
AnchorPane paneContent = new AnchorPane();
for (int j = 0; j < 2; j++) {
TextField text = new TextField();
paneContent.getChildren().add(text);
text.setLayoutX(8);
text.setLayoutY(j*30);
}
pane.setCollapsible(false);
pane.setContent(paneContent);
pane.setLayoutY(i*100);
content.getChildren().add(pane);
}
root.getChildren().add(scrollPane);
scrollPane = new ScrollPane();
content = new Pane();
scrollPane.setContent(content);
for (int i = 0; i < 3; i++) {
TitledPane pane = new TitledPane();
AnchorPane paneContent = new AnchorPane();
pane.setContent(paneContent);
pane.setPrefWidth(200);
pane.setPrefHeight(80);
pane.setCollapsible(false);
pane.setLayoutY(i*100);
content.getChildren().add(pane);
}
root.getChildren().add(scrollPane);
Scene scene = new Scene(root, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) { launch(); }
}
Run Code Online (Sandbox Code Playgroud)
对于第二个titledpane一切都很好,但首先没有.我需要感知可见(自动滚动滚动窗格),控制它们何时获得焦点.
| 归档时间: |
|
| 查看次数: |
659 次 |
| 最近记录: |