2017-08-01 1 views
0

ControlsFX(v8.40.12)のSpreadsheetViewコントロールでいくつかのテストを行いましたが、他のタイプのオブジェクトをセルに追加することはできません。テキスト。SpreadsheetViewセルにDatePickerやButton、さらにはImageを配置できません

コードに問題がありますか、何か不足していますか? 誰かが私にそのことをどうやって伝えることができますか?

私はSpreadsheetCellBase、SetGraphicおよびsetCellValueを使用しています。

いくつかのコメントはポルトガル語で、申し訳ありません!

多くのありがとうございます。

package javafx_controlsfx_spreadsheetview; 

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.DatePicker; 
import javafx.scene.control.Alert; 
import javafx.scene.image.Image; 
import javafx.scene.image.ImageView; 
import javafx.stage.Stage; 
import javafx.collections.FXCollections; 
import javafx.collections.ObservableList; 
import java.util.Arrays; 
import java.util.List; 
import org.controlsfx.control.spreadsheet.GridBase; 
import org.controlsfx.control.spreadsheet.Picker; 
import org.controlsfx.control.spreadsheet.SpreadsheetCell; 
import org.controlsfx.control.spreadsheet.SpreadsheetCellBase; 
import org.controlsfx.control.spreadsheet.SpreadsheetView; 

public class JavaFX_ControlsFX_SpreadsheetView extends Application 
{ 
    @Override 
    public void start(Stage primaryStage) 
    { 
    int numLinhas = 25; 
    int numColunas = 20; 
    GridBase grelha = new GridBase(numLinhas, numColunas); 
    ObservableList<ObservableList<SpreadsheetCell>> linhas = FXCollections.<ObservableList<SpreadsheetCell>>observableArrayList(); 
    ObservableList<SpreadsheetCell> celulas = null; 
    SpreadsheetCellBase celula; 

    for (int linha = 0; linha < grelha.getRowCount(); linha++) 
    { 
     celulas = FXCollections.<SpreadsheetCell>observableArrayList(); 
     for (int coluna = 0; coluna < grelha.getColumnCount(); coluna++) 
     { 
     celula = new SpreadsheetCellBase(linha, coluna, 1, 1); 
     celula.setItem("---"); 
     celulas.add(celula); 
     } 
     linhas.add(celulas); 
    } 
    grelha.setRows(linhas); 

    SpreadsheetView sv = new SpreadsheetView(grelha); 

    // Atribui um valor à (6ª Linha -> 6)/8ª Coluna -> H). 
    grelha.setCellValue(5, 7, "Pedro"); 

    // Atribui um valor à (5ª Linha -> 5)/13ª Coluna -> M). 
    grelha.setCellValue(4, 12, 164.58); 

    // Popula a Grelha de A1 a A6, com os países definidos na Lista abaixo criada. 
    List<String> countries = Arrays.asList("China", "França", "Nova Zelândia", "Escócia", "Alemanha", "Canada"); 
    byte r = 0; 
    for (String c : countries) 
    { 
     grelha.setCellValue(r, 0, c); 
     r++; 
    } 




    // Part of the code that doesn't work! 

    celula = new SpreadsheetCellBase(3, 7, 1, 1); 
    celula.setGraphic(new Button("Teste")); 
    grelha.setCellValue(3, 7, celula); 


    SpreadsheetCellBase cell = new SpreadsheetCellBase(10, 4, 1, 1); 
    cell.setGraphic(new DatePicker()); 


    SpreadsheetCellBase cell2 = new SpreadsheetCellBase(5, 9, 1, 1); 
    cell2.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("pic.png")))); 

    // ------------------------------------- 




    sv.getStylesheets().add(getClass().getResource("Styles.css").toExternalForm()); 

    Scene scene = new Scene(sv, 1300, 800); 

    primaryStage.setTitle("JavaFX - ControlsFX (SpreadsheetView)"); 
    primaryStage.setScene(scene); 
    primaryStage.show(); 
    } 


    public static void main(String[] args) 
    { 
    launch(args); 
    } 
} 

あり同様のポストがあるが、それはこの問題について私に答えを与えるものではありません:すべての How to change text in cells (SpreadsheetView by ControlsFX)?

答えて

1

まず、我々は画像とCSSを逃しているので、あなたのコードがコンパイルされていませんスタイルシート。コードをリンクするときは、コードを直接動作させるようにしてください。

問題については、新しいSpreadsheetCellを作成していますが、グリッドには追加しないでください!

SpreadsheetCellBase cell = new SpreadsheetCellBase(10, 4, 1, 1); 
cell.setItem(null); 
cell.setGraphic(new DatePicker()); 

セルがグリッドに与えられない限り、これは絶対に正しいです。あなたが探しているセルは、上記のループにすでに追加されています。だからあなたがする必要があるのは、それにアクセスして、datePickerを次のように設定することです:

linhas.get(10).get(4).setGraphic(new DatePicker()); 

次に動作します。

for (int linha = 0; linha < grelha.getRowCount(); linha++) 
    { 
     celulas = FXCollections.<SpreadsheetCell>observableArrayList(); 
     for (int coluna = 0; coluna < grelha.getColumnCount(); coluna++) 
     { 
     celula = SpreadsheetCellType.STRING.createCell(linha, coluna, 1, 1, "---"); 
//  celula.setItem("---"); 
     celulas.add(celula); 
     } 
     linhas.add(celulas); 
    } 

はまた、我々はあなたがあなたの質問をすることができControlsFXグーグルグループを持っていることに注意してください::サイドノートで

は、それが直接SpreadsheetCellBaseをインスタンス化するのではなく、SpreadsheetCellTypeとSpreadsheetCellで作業する方が良いでしょう https://groups.google.com/forum/#!forum/controlsfx-dev 私たちはそこに通知を受けますので、通常は応答が早くなります;)

関連する問題