2017-07-26 38 views
1

我有7列的Vaadin格列長文本:Vaadin電網如何包裝在

Grid grid = new Grid<>(); 
grid.setSizeFull(); 

grid.addColumn(User::getUserName).setCaption("Name").setExpandRatio(2); 
grid.addColumn(User::getLastName).setCaption("Last Name").setExpandRatio(1);      
grid.addColumn(User::getAge).setCaption("Age").setExpandRatio(2); 
grid.addColumn(User::getWork).setCaption("Work").setExpandRatio(1); 
grid.addColumn(User::getJobTitle).setCaption("Job Title").setExpandRatio(1); 
grid.addColumn(User::getSalary).setCaption("Salary").setExpandRatio(1); 
grid.addColumn(User::getOther).setCaption("Other").setExpandRatio(1); 

我需要的是設置列寬的方式 - 所有7將有一個屏幕上顯示。 現在用我的代碼,它的工作方式是,如果任何列單元格的文本內容非常長 - 最後一列不顯示在屏幕上,屏幕必須水平滾動。

我試圖使用方法setWidth()和,因爲它需要在像素值的網格視圖可以在各種瀏覽器和畫面不同。

我需要做的是確保我的網格看起來在不同的屏幕和不同細胞值的方法相同。

+0

你的問題不是列擴展比例是如何包裹文字。 – efekctive

+0

請您詳細說明一下嗎? – Lena

+0

如果expandRatio成立的文本很短,它正在工作。如果文字太長,則展開比率會中斷。嘗試玩單元格的高度,看看它是否有幫助 – efekctive

回答

0

最近,我有同樣的情況,這是我的解決方案:

電網配置

Grid<Item> gridItem = new Grid<>(); 
gridItem.setRowHeight(50.0); 

色譜柱配置

gridItem.addComponentColumn(item -> { 
      Label label = new Label(); 
      label.setValue(item.getText()); 
      label.setWidthUndefined(); 
      label.setStyleName(ValoTheme.LAYOUT_HORIZONTAL_WRAPPING); 
      return label; 
     }) 
     .setCaption("Item") 
     .setWidth(380.0); 

結果:

enter image description here