Javafx Can';不要在电子表格视图单元格中放置日期选择器、按钮甚至图像
我使用ControlsFX(v8.40.12)中的SpreadsheetView控件进行了一些测试,除了文本之外,我无法向单元格添加任何其他类型的对象 代码有问题吗,或者我只是缺少了什么? 有人能告诉我怎么做吗 我使用的是SpreadsheetCellBase、SetGraphic和setCellValue 有些评论是葡萄牙语的,对不起 非常感谢Javafx Can';不要在电子表格视图单元格中放置日期选择器、按钮甚至图像,javafx,controlsfx,Javafx,Controlsfx,我使用ControlsFX(v8.40.12)中的SpreadsheetView控件进行了一些测试,除了文本之外,我无法向单元格添加任何其他类型的对象 代码有问题吗,或者我只是缺少了什么? 有人能告诉我怎么做吗 我使用的是SpreadsheetCellBase、SetGraphic和setCellValue 有些评论是葡萄牙语的,对不起 非常感谢 package javafx_controlsfx_spreadsheetview; import javafx.application.Appli
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);
}
}
package javafx\u controlsfx\u电子表格视图;
导入javafx.application.application;
导入javafx.scene.scene;
导入javafx.scene.control.Button;
导入javafx.scene.control.DatePicker;
导入javafx.scene.control.Alert;
导入javafx.scene.image.image;
导入javafx.scene.image.ImageView;
导入javafx.stage.stage;
导入javafx.collections.FXCollections;
导入javafx.collections.ObservableList;
导入java.util.array;
导入java.util.List;
导入org.controlsfx.control.spreadsheet.GridBase;
导入org.controlsfx.control.spreadsheet.Picker;
导入org.controlsfx.control.spreadsheet.SpreadsheetCell;
导入org.controlsfx.control.spreadsheet.SpreadsheetCellBase;
导入org.controlsfx.control.spreadsheet.spreadsheet视图;
公共类JavaFX_ControlsFX_电子表格视图扩展了应用程序
{
@凌驾
公共无效开始(阶段primaryStage)
{
int numLinhas=25;
int numColunas=20;
GridBase grelha=新的GridBase(numLinhas,numColunas);
ObservableList linhas=FXCollections.observableArrayList();
ObservableList celulas=null;
花柱基部;
for(int linha=0;linha6)/8-科鲁纳->H)。
grelha.setCellValue(5,7,“Pedro”);
//阿提比乌姆山谷(5-林哈->5)/13-科鲁纳->米)。
grelha.setCellValue(4,12,164.58);
//一个a 1和a 6的群体,定义为a 1和a 6。
List countries=Arrays.asList(“中国”、“法国”、“新泽兰迪亚”、“Escócia”、“阿莱曼哈”、“加拿大”);
字节r=0;
用于(字符串c:国家)
{
grelha.setCellValue(r,0,c);
r++;
}
//部分代码不起作用!
celula=新的电子表格单元基础(3,7,1,1);
celula.setGraphic(新按钮(“测试仪”);
grelha.setCellValue(3,7,celula);
SpreadsheetCellBase单元=新的SpreadsheetCellBase单元(10,4,1,1);
cell.setGraphic(新的日期选择器());
SpreadsheetCellBase cell2=新的SpreadsheetCellBase(5,9,1,1);
cell2.setGraphic(新图像视图(新图像(getClass().getResourceAsStream(“pic.png”)));
// -------------------------------------
sv.getStylesheets().add(getClass().getResource(“Styles.css”).toExternalForm());
场景=新场景(sv,1300800);
setTitle(“JavaFX-ControlsFX(电子表格视图)”;
初级阶段。场景(场景);
primaryStage.show();
}
公共静态void main(字符串[]args)
{
发射(args);
}
}
有一个类似的帖子,但它没有给我关于这个问题的答案:
首先,您的代码没有编译,因为我们缺少图片和css样式表。当你链接一个代码时,试着让它直接工作 关于您的问题,您正在创建新的电子表格单元格,但从未将其添加到网格中
SpreadsheetCellBase cell = new SpreadsheetCellBase(10, 4, 1, 1);
cell.setItem(null);
cell.setGraphic(new DatePicker());
这是绝对正确的,除非单元格从未被赋予网格。您正在查找的单元格已添加到上面的循环中。因此,您只需访问它,并将日期选择器设置为:
linhas.get(10).get(4).setGraphic(new DatePicker());
那就行了
另一方面,最好使用SpreadsheetCellType和SpreadsheetCell,而不是直接实例化SpreadsheetCellBase:
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);
}
for(int-linha=0;linha
另外请注意,我们有一个ControlsFX google小组,您可以在其中提问:
我们在那里得到通知。。因此,通常响应速度更快;) 首先,您的代码没有编译,因为我们缺少图片和css样式表。当你链接一个代码时,试着让它直接工作 关于您的问题,您正在创建新的电子表格单元格,但从未将其添加到网格中
SpreadsheetCellBase cell = new SpreadsheetCellBase(10, 4, 1, 1);
cell.setItem(null);
cell.setGraphic(new DatePicker());
这是绝对正确的,除非单元格从未被赋予网格。您正在查找的单元格已添加到上面的循环中。因此,您只需访问它,并将日期选择器设置为:
linhas.get(10).get(4).setGraphic(new DatePicker());
那就行了
另一方面,最好使用SpreadsheetCellType和SpreadsheetCell,而不是直接实例化SpreadsheetCellBase:
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);
}
for(int-linha=0;linha
另外请注意,我们有一个ControlsFX google小组,您可以在其中提问:
我们在那里得到通知。。因此,通常响应速度更快;)