1
내 문제는 내가 그들이 한마음으로 스크롤하려는 두 개의 수평 스크롤 막대를 가지고 내가 사용 해봤입니다 최대 값은 1.0
이고 bar2
의 최대 값은 102.5
입니다. 따라서 문제는 스크롤 할 때 bar2
일 때 bar1
은 값이 크게 달라져서 많이 움직입니다. value 속성을 바인딩하기 전에 setMin
, setMax
, setUnitIncrement
, setBlockIncrement
을 사용해 보았습니다. 하지만 작동하지 않습니다. 후자는 아니지만 전자 정규화 때문에동기화 두 스크롤 막대 자바 FX
public class DynamicTableView extends Application {
private Scene scene;
private VBox root;
private ScrollPane scPane;
private static final int N_COLS = 10;
private static final int N_ROWS = 10;
private Button button;
public void start(Stage stage) throws Exception {
root = new VBox();
scPane = new ScrollPane();
Label lbl = new Label("Dynamic Table Dynamic Table Dynamic Table Dynamic Table Dynamic Table Dynamic Table Dynamic Table Dynamic Table Dynamic Table Dynamic Table Dynamic Table Dynamic Table Dynamic Table Dynamic Table Dynamic Table Dynamic Table Dynamic Table");
scPane.setContent(lbl);
root.getChildren().add(scPane);
TestDataGenerator dataGenerator = new TestDataGenerator();
TableView<ObservableList<String>> tableView = new TableView<>();
// add columns
List<String> columnNames = dataGenerator.getNext(N_COLS);
for (int i = 0; i < columnNames.size(); i++) {
final int finalIdx = i;
TableColumn<ObservableList<String>, String> column = new TableColumn<>(
columnNames.get(i)
);
column.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(param.getValue().get(finalIdx)));
tableView.getColumns().add(column);
}
// add data
for (int i = 0; i < N_ROWS; i++) {
tableView.getItems().add(
FXCollections.observableArrayList(
dataGenerator.getNext(N_COLS)
)
);
}
root.getChildren().add(tableView);
tableView.setPrefHeight(200);
button = new Button("Delete");
button.setOnAction(event -> { tableView.getItems().clear();});
root.getChildren().add(button);
Scene scene = new Scene(root, 600, 600);
stage.setScene(scene);
stage.show();
for(Node node1: scPane.lookupAll(".scroll-bar"))
{
if(node1 instanceof ScrollBar)
{
ScrollBar scrollBar1 = (ScrollBar)node1;
if(scrollBar1.getOrientation() == Orientation.HORIZONTAL)
{
for(Node node2: tableView.lookupAll(".scroll-bar"))
{
if(node2 instanceof ScrollBar)
{
ScrollBar scrollBar2 = (ScrollBar)node2;
if(scrollBar2.getOrientation() == Orientation.HORIZONTAL)
{
scrollBar2.valueProperty().bindBidirectional(scrollBar1.valueProperty());
break;
}
}
}
}
}
}
}
public static void main(String[] args) {
launch(args);
}
private static class TestDataGenerator {
private static final String[] LOREM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tempus cursus diam ac blandit. Ut ultrices lacus et mattis laoreet. Morbi vehicula tincidunt eros lobortis varius. Nam quis tortor commodo, vehicula ante vitae, sagittis enim. Vivamus mollis placerat leo non pellentesque. Nam blandit, odio quis facilisis posuere, mauris elit tincidunt ante, ut eleifend augue neque dictum diam. Curabitur sed lacus eget dolor laoreet cursus ut cursus elit. Phasellus quis interdum lorem, eget efficitur enim. Curabitur commodo, est ut scelerisque aliquet, urna velit tincidunt massa, tristique varius mi neque et velit. In condimentum quis nisi et ultricies. Nunc posuere felis a velit dictum suscipit ac non nisl. Pellentesque eleifend, purus vel consequat facilisis, sapien lacus rutrum eros, quis finibus lacus magna eget est. Nullam eros nisl, sodales et luctus at, lobortis at sem.".split(" ");
private int curWord = 0;
List<String> getNext(int nWords) {
List<String> words = new ArrayList<>();
for (int i = 0; i < nWords; i++) {
if (curWord == Integer.MAX_VALUE) {
curWord = 0;
}
words.add(LOREM[curWord % LOREM.length]);
curWord++;
}
return words;
}
}
}
문제를 보여주는 실행 가능한 예제를 제공하십시오 (https://stackoverflow.com/help/how-to-ask 참조) – kleopatra
을 어떻게 또한 "참조 [MCVE]를 만드십시오. –
은 크기 조정이 다른 것처럼 보입니다. scrollPane에서 max = 1.0으로 정규화되었지만 tableView에서는 원시 픽셀입니다. 이상하게도 값은 임의의 값으로 설정 될 수 있지만 실제 스크롤 할 때 다시 설정됩니다. 즉, 테이블을 스크롤하면 상한값 (1.0)으로 즉시 이동하고 창을 스크롤하면 테이블이 즉시 낮은 바운드 (매우 0.0) – kleopatra