2014-07-18 3 views
3

트랜 시트 블 셀의 텍스트를 인접한 셀로 넘치고 싶습니다. 나는 테이블이나 테이블에 스팬 함수가 없다는 것을 잠시 전에 읽었을 것이라고 생각하지만, CSS를 통해 수행 될 수 있습니다.JavaFX Table/TreeTable 셀 오버플로

이미지를 참조하십시오. 첫 번째 셀의 날짜가 다른 셀보다 길어서 읽을 수있게하고 싶습니다.

http://imgur.com/KvK0adK

은 내가 -overflow를 사용하는 것이라고 생각 : 보이는;는하지만 오라클 설명서를 읽어 :

자바 FX CSS는 플로트, 위치, 오버 플로우, 그리고 폭으로 CSS 레이아웃 속성을 지원하지 않습니다.

누구나 올바른 방향으로 나를 가리킬 수 있습니까? CSS가 더 좋지만 사용자 정의 TreeTableRow가 올바른 해결책일까요?

미리 감사드립니다.

+0

관련 기능 요청 들어, 참조 RT-22,593 표기 팝 오버 플로우 디스플레이 (https://javafx-jira.kenai.com/browse/RT-22593). – jewelsea

+0

그 모양은 비슷하지만 다르다. (그들은 조만간에 나오지 않는다.) 사용자 정의 treeTableRow가 작동한다고 생각합니까? (BTW ... 당신의 모든 도움에 대한 당신의 남자가 ... 그래서 javafx를 빨리 배울 수있었습니다. 당신의 작업에 감사드립니다.) – Dustin

답변

2

샘플 솔루션 여기

가있는 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 해킹은 단순한 일이었습니다. 첫 번째 줄의 마지막 이름은 다음 칼럼에 오버 플로우 방법

샘플 코드

다음

행동을, 당신은 볼 수 있습니다. 여기에 코드의 양에 대한

overflow

죄송합니다.

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); 
     } 
    } 
} 
+0

안녕하세요, 잘됐다. "-fx-table-cell-border-color : transparent;"를 추가했습니다. CSS에 수직 그리드 선을 숨기고 완벽 해 보인다. 감사 – Dustin

관련 문제