솔루션
표준 TableCell의 기본 오버런 행동은 문자열이 잘 렸습니다 나타 내기 위해 문자열의 끝에 문자열 표시 ...
의 절단하는 것입니다. JavaFX의 모든 Labeled 컨트롤은 이러한 방식으로 작동합니다.
질문에있는 예제는 문자열 중간에 ...
줄임표가 있습니다. 적절한 세포 공장에 의해 생성 된 셀이, set the overrun style을 달성하기 :
ellipsises에 대해 표시되는 텍스트 문자열은 해당 셀 공장에 의해 생성 된 세포에
setting a new ellipsis string에 의해 약간 변형 될 수
setTextOverrun(OverrunStyle.CENTER_WORD_ELLIPSIS);
:
setEllipsisString(ellipsisString);
이 방법을 보여줍니다
간단한 테이블 셀은 다음과 같습니다
class CenteredOverrunTableCell extends TableCell<Person, String> {
public CenteredOverrunTableCell() {
this(null);
}
public CenteredOverrunTableCell(String ellipsisString) {
super();
setTextOverrun(OverrunStyle.CENTER_WORD_ELLIPSIS);
if (ellipsisString != null) {
setEllipsisString(ellipsisString);
}
}
@Override protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setText(item == null ? "" : item);
}
}
샘플 응용 프로그램
CenteredOverrunTableCell
은 다음 샘플 응용 프로그램에서 사용됩니다.
- 첫 번째 이름 열은 중앙에 텍스트를 elides 및 성 열은 중앙에 텍스트를 elides하지만 사용자 정의 줄임표 문자열을 제공하지
<--->
- 의 사용자 지정 생략 문자열을 사용합니다.
- 전자 메일 열은 오버런 문자열의 끝에
...
줄임표를 배치하는 기본 오버런 정책과 줄임표 문자열을 사용합니다.
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.*;
import javafx.geometry.Insets;
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;
import javafx.util.Callback;
public class ElidedTableViewSample extends Application {
private TableView<Person> table = new TableView<>();
private final ObservableList<Person> data =
FXCollections.observableArrayList(
new Person("Jacob", "Smith", "[email protected]"),
new Person("Isabella", "Johnson", "[email protected]"),
new Person("Ethangorovichswavlowskikaliantayaprodoralisk", "Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch", "[email protected]ch.com"),
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) {
stage.setTitle("Table View Sample");
stage.setWidth(470);
stage.setHeight(500);
final Label label = new Label("Address Book");
label.setFont(new Font("Arial", 20));
TableColumn firstNameCol = new TableColumn("First Name");
firstNameCol.setCellValueFactory(
new PropertyValueFactory<Person, String>("firstName"));
firstNameCol.setCellFactory(new Callback<TableColumn<Person, String>, TableCell<Person, String>>() {
@Override public TableCell<Person, String> call(TableColumn<Person, String> p) {
return new CenteredOverrunTableCell("<--->");
}
});
TableColumn lastNameCol = new TableColumn("Last Name");
lastNameCol.setCellValueFactory(
new PropertyValueFactory<Person, String>("lastName"));
lastNameCol.setCellFactory(new Callback<TableColumn<Person, String>, TableCell<Person, String>>() {
@Override public TableCell<Person, String> call(TableColumn<Person, String> p) {
return new CenteredOverrunTableCell();
}
});
TableColumn emailCol = new TableColumn("Email");
emailCol.setCellValueFactory(
new PropertyValueFactory<Person, String>("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);
table.setColumnResizePolicy(
TableView.CONSTRAINED_RESIZE_POLICY
);
Scene scene = new Scene(vbox);
stage.setScene(scene);
stage.show();
}
class CenteredOverrunTableCell extends TableCell<Person, String> {
public CenteredOverrunTableCell() {
this(null);
}
public CenteredOverrunTableCell(String ellipsisString) {
super();
setTextOverrun(OverrunStyle.CENTER_WORD_ELLIPSIS);
if (ellipsisString != null) {
setEllipsisString(ellipsisString);
}
}
@Override protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setText(item == null ? "" : item);
}
}
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);
}
}
}
'setTextOverrun는()'내가 찾던 정확히 무엇이다! 아주 잘 답변 해 주셔서 대단히 감사합니다! 내가 할 수 있다면 +10! – SnakeDoc