샘플 솔루션 여기
가있는 TableView에 대한 오버 플로우 전지, 당신은 아마 TreeTableView을 위해 그것을 적용 할 수있다. 수신기는 어떤 클립을 제거 OverflowCell 생성자 첨가되도록
class OverflowCell extends TableCell<Person, String> {
private Label overflowLabel = new Label();
private Group overflowGroup = new Group(overflowLabel);
public OverflowCell() {
// destroy the clip.
clipProperty().addListener((observable, oldClip, newClip) -> {
if (newClip != null) {
setClip(null);
}
});
}
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setGraphic(null);
} else {
overflowLabel.setText(item);
setGraphic(
overflowGroup
);
}
}
}
통상의 TableView에서 세포 클리핑, 세포에 첨가 하였다. updateItem 호출은 그룹을 사용하여 레이블의 크기가 기본 크기보다 작아지고 생략되지 않도록합니다.
아마도 다른 방법이있을 수 있습니다. 사용자 정의 행 팩토리가 대체 솔루션 일 수 있습니다. 이 OverflowCell 해킹은 단순한 일이었습니다. 첫 번째 줄의 마지막 이름은 다음 칼럼에 오버 플로우 방법
샘플 코드
다음
행동을, 당신은 볼 수 있습니다. 여기에 코드의 양에 대한
죄송합니다.
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class TableCellOverflow extends Application {
private TableView<Person> table = new TableView<>();
private final ObservableList<Person> data =
FXCollections.observableArrayList(
new Person("Jacob", "Krzyzanowski", ""),
new Person("Isabella", "Johnson", "[email protected]"),
new Person("Ethan", "Williams", "[email protected]"),
new Person("Emma", "Jones", "[email protected]"),
new Person("Michael", "Brown", "[email protected]")
);
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
Scene scene = new Scene(new Group());
stage.setTitle("Table View Sample");
table.setPrefHeight(200);
final Label label = new Label("Address Book");
label.setFont(new Font("Arial", 20));
TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name");
firstNameCol.setMaxWidth(80);
firstNameCol.setCellValueFactory(
new PropertyValueFactory<>("firstName"));
firstNameCol.getStyleClass().add("left-header");
TableColumn<Person, String> lastNameCol = new TableColumn<>();
lastNameCol.setMaxWidth(60);
lastNameCol.setCellValueFactory(
new PropertyValueFactory<>("lastName"));
lastNameCol.setCellFactory(param -> new OverflowCell());
TableColumn<Person, String> emailCol = new TableColumn<>("Email");
emailCol.setMaxWidth(100);
emailCol.setCellValueFactory(
new PropertyValueFactory<>("email"));
table.setItems(data);
table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(10));
vbox.getChildren().addAll(label, table);
((Group) scene.getRoot()).getChildren().addAll(vbox);
stage.setScene(scene);
stage.show();
}
class OverflowCell extends TableCell<Person, String> {
private Label overflowLabel = new Label();
private Group overflowGroup = new Group(overflowLabel);
public OverflowCell() {
// destroy the clip.
clipProperty().addListener((observable, oldClip, newClip) -> {
if (newClip != null) {
setClip(null);
}
});
}
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setGraphic(null);
} else {
overflowLabel.setText(item);
setGraphic(
overflowGroup
);
}
}
}
public static class Person {
private final SimpleStringProperty firstName;
private final SimpleStringProperty lastName;
private final SimpleStringProperty email;
private Person(String fName, String lName, String email) {
this.firstName = new SimpleStringProperty(fName);
this.lastName = new SimpleStringProperty(lName);
this.email = new SimpleStringProperty(email);
}
public String getFirstName() {
return firstName.get();
}
public void setFirstName(String fName) {
firstName.set(fName);
}
public String getLastName() {
return lastName.get();
}
public void setLastName(String fName) {
lastName.set(fName);
}
public String getEmail() {
return email.get();
}
public void setEmail(String fName) {
email.set(fName);
}
}
}
관련 기능 요청 들어, 참조 RT-22,593 표기 팝 오버 플로우 디스플레이 (https://javafx-jira.kenai.com/browse/RT-22593). – jewelsea
그 모양은 비슷하지만 다르다. (그들은 조만간에 나오지 않는다.) 사용자 정의 treeTableRow가 작동한다고 생각합니까? (BTW ... 당신의 모든 도움에 대한 당신의 남자가 ... 그래서 javafx를 빨리 배울 수있었습니다. 당신의 작업에 감사드립니다.) – Dustin