简介(JDK8)
本篇文章是根据SpreadsheetView官方API和查看源码的基础上,以及在项目中的应用的经验,供工友们学习参考。
公共类SpreadsheetView扩展控件是类似于JavaFx TableView的一个控件,但是具有不同的功能和用例。目的是要拥有一个强大的网格,可以在其中写入检索数据。
特征
1.单元格可以跨行和跨列。
2.可以固定行和列(只有没有跨列的单元格才能固定)。
3.可以显示或隐藏行头/列头。
4.可以通过拖动调整行的高度。
5.可以通过拖动选择多个单元格。
6.右键可使用复制粘贴上下文菜单。通用的快捷方式也可以使用。
构造函数
SpreadsheetView() 创建一个默认表格(100行,15列,列宽100,每个单元格内容为“toto”)的控件。注:默认行高30 |
SpreadsheetView(Grid grid) 指定Grid网格视图的控件,注:使用此方法 |
公共方法
返回值类型 | 方法和说明 |
void | setCellGraphicFactory(CellGraphicFactory cellGraphicFactory)
|
CellGraphicFactory | getCellGraphicFactory()
|
boolean | isRowHidden(int row)
|
BitSet | getHiddenRows()
|
ObjectProperty<BitSet> | hiddenRowsProperty()
|
void | setHiddenRows(BitSet hiddenRows)
|
void | setHiddenColumns(BitSet hiddenColumns)
|
boolean | isColumnHidden(int column)
|
BitSet | getHiddenColumns() |
ObjectProperty<BitSet> | hiddenColumnsProperty() |
int | getFilteredRow() |
void | setFilteredRow(Integer row) |
void | hideRow(int row) |
void | hideColumn(SpreadsheetColumn column) |
void | showRow(int row) |
void | showColumn(SpreadsheetColumn column) |
int | getFilteredRow(int modelRow) |
int | getViewColumn(int modelColumn) |
int | getModelColumn(int viewColumn) |
int | getViewRow(int modelRow) |
int | getModelRow(int viewRow) |
int | getRilteredSourceIndex(int viewRow) |
int | getRowSpan(SpreadsheetCell cell, int index) |
int | getReverseRowSpan(SpreadsheetCell cell, int index) |
int | getRowSpanFilter(SpreadsheetCell cell) |
ObservableList<ObservableList<SpreadsheetCell>> | getItems() 获取工作表的对象(二维数组) |
int | getColumnSpan(SpreadsheetCell cell) |
Double | getZoomFactor() |
void | setZoomFactor(Double zoomFactor) |
DoubleProperty | zoomFactorProperty() |
void | incrementZoom() |
void | decrementZoon() |
void | edit(int row, SpreadsheetColumn column) |
Comparator | getComparator() |
ObjectProperty<Comparator<? super ObservableList<SpreadsheetCell>>> | comparatorProperty() |
void | setComparator(Comparator<ObservableList<SpreasheetCell>> comparator) |
void | setGrid(Grid grid) 为SpreadsheetView设置一个新的网格 |
TablePosition<ObservableList<SpreadsheetCell>, ?> | getEditingCell() 返回一个当前正在编辑单元格的TablePosition |
ReadOnlyObjectProperty<TablePosition<ObservableList<SpreadsheetCell>, ?>> | editingCellProperty() |
ObservableList<SpreadsheetColumn> | getColumns() 返回一个不可修改的SpreadsheetColumn列表 |
Grid | getGrid() 返回SpreadsheetView使用的Grid数据模型 |
ReadOnlyObjectProperty<Grid> | gridProperty() 返回以恶ReadOnlyObjectProperty包含SpreadsheetView中使用的当前的Grid |
ObservableList<Integer> | getFixedRows() 可以通过修改此列表来修复或取消修复行 |
boolean | isRowFixable(int row) 设置该行是否可以固定 |
boolean | areRowsFixable(List<? extends Integer> list) |
boolean | isFixingRowsAllowed() 返回是否允许更改为固定行 |
void | setFixingRowsAllowed(boolean b) 如果设置为true,将允许用户修复和取消修复行 |
ReadOnlyBooleanProperty | fixingRowsAllowedProperty() 返回与允许固定或取消固定某些行相关联的布尔属性 |
ObservableList<SpreadsheetColumn> | getFixedColumns() 可以通过修改此列表来修复或者取消修复列 |
boolean | isColumnFixable(int columnIndex) 设置此列是否可以固定 |
boolean | areSpreadsheetColumnsFixable(List<? extends SpreadsheetColumn> list) |
boolean | areColumnsFixable(List<? extends Integer> list) |
boolean | isFixingColumnsAllowed() 返回是否允许更改为“固定”列 |
void | setFixingColumnsAllowed(boolean b) 如果设置为true,将允许用户修复和取消修复列 |
ReadOnlyBooleanProperty | fixingColumnsAllowedProperty() 返回与允许固定或取消固定某些列关联的布尔属性 |
void | setShowColumnHeader(boolean b) 激活和停用列标题 |
boolean | isShowColumnHeader() 是否显示列标题 |
BooleanProperty | showColumnHeaderProperty() 与列标题关联的BooleanProperty |
void | setShowRowHeader(boolean b) 激活和停用行标题 |
boolean | isShowRowHeader() 是否显示行标题 |
BooleanProperty | showRowHeaderProperty() 与行标题关联的BooleanProperty |
DoubleProperty | rowHeaderWidthProperty() |
void | setRowHeaderWidth(double value) |
double | getRowHeaderWidth() |
ObservableMap<Integer, picker> | getRowPickers() |
ObservableMap<Integer, Picker> | getColumnPickers() |
void | resizeRowsToFitContent() 此方法将计算每条线的最佳高度 |
void | resizeRowsToMaximum() 该方法将首先应用resizeRowsToFitContent(),然后采用最高高度并将起应用到每一行 就像resizeRowsToFitContent()该方法一样,该方法可能回降低大网格上的性能 |
void | resizeRowsToDefault() 此方法将擦除对行的高度所做的所有更改,并将所有行的高度设置回其在模型网格中定义的默认高度 注:手动设置修改行高后,可以使用此方法让界面刷新 |
double | getRowHeight(int row) |
SpreadsheetViewSelectionModel | getSelectionModel() 返回SpreadsheetView使用的selectionModel |
void | scrollToRow(int row) |
void | setVBarValue(double value) |
void | setHBarValue(double value) |
void | setHBarValue(double value, int attempt) |
double | getVBarValue() |
double | getHBarValue() |
void | scrollToColumn(SpreadsheetColumn column) |
void | scrollToColumnIndex(int modelColumn) |
Optional<SpreadsheetCellEditor> | getEditor(SpreadsheetCellType<?> cellType) 返回与CellType关联的编辑器 |
void | setEditable(boolean b) 设置属性的值可编辑 |
boolean | isEditable() 获取可编辑属性的值 |
BooleanProperty | editableProperty() 指定此SpreadsheetView是否可编辑,当且仅当SpreadsheetView及其SpreadsheetCell内部控件都可编辑时,SpreadsheetCell才可以进入其编辑状态 |
ObjectProperty<Node> | placeholderProperty() |
void | setPlaceholder(Node placeholder) |
Node | getPlaceholder() |
void | copyClioboard() 将当前选择放入剪贴板 |
void | pasteClipboard() 尝试将clipBoard粘贴到指定位置 |
ContextMenu | getSpreadsheetViewContextMenu() 在右键上创建具有两个选项的菜单:复制/黏贴,开发人员可以针对自定义行为覆盖此菜单 |
void | deleteSelectedCells() 在SpreadsheetView上按下“删除”键时,将调用此方法 |
SpreadsheetView.SpanType | getSpanType(int rowIndex, int modelColumn) 返回一个单元格的SpreadsheetView.SpanType,这是一个快捷方式Grid.getSpanType(SpreadsheetView, int, int) |
static class | ColumnWidthEvent 嵌套类,描述列的宽度事件 eg:
|
static class | RowHeightEvent 嵌套类,描述行的高度事件 eg:
|
GridBase
构造函数
GridBase(int rowCount, int columnCount) 创建具有固定数量的行和列的网格。 |
公共方法
返回值类型 | 方法和说明 |
ObservableList<ObservableList<SpreadsheetCell>> | getRows() 返回SpreadsheetCell实例的二维数组 |
void | setCellValue(int modelRow, int column, Object value) 更改单元格的值,并触发GridChange事件 |
int | getRowCount() |
int | getColumnCount() |
double | getRowHeight(int row) 返回一行的高度 |
void | setRowHeightCallBack(CallBack<Integer, Double> rowHeight) 为此网格设置一个新值以指定每行的高度,可以使用内部工具类MapBasedRowHeightFactory |
ObservableList<String> | getRowHeaders() 返回要在行标题中显示的字符串的列表 |
ObservableList<String> | getColumnHeaders() 返回要在列标题中显示的字符串的列表 |
BooleanProperty | lockedProperty() 返回与锁定网格状态关联的BooleanProperty |
boolean | isLocked() 返回此Grid ID是否已锁定 |
void | setLocked(Boolean lock) 锁定或解锁此网格 |
void | spanRow(int count, int rowIndex, int colIndex) 通过行数跨行位于rowIndex和colIndex的单元格 |
void | spanColumn(int count, int rowIndex, int colIndex) 按列数跨过rowIndex和colIndex处的单元格的列数 |
void | setRows(Collection<ObservableList<SpreadsheetCell>> rows) 此方法设置网格使用的行,并更新rowCount |
void | setResizableRows(BitSet resizableRow) |
boolean | isRowResizable(int row) |
boolean | isDisplaySelection() |
void | setDisplaySelection(boolean value) |
BooleanProperty | displaySelectionProperty() |
void | setCellDisplaySelection(int row, int column, boolean displaySelection) |
boolean | isCellDisplaySelection(int row, int column) |
<E extends GridChange> void | addEventHandler(EventType<E> eventType, EventHandler<E> eventHandler) 将事件处理程序注册到此网格中 |
<E extends GridChange> void | removeEventHanlder(EventType<E> eventType, EventHandler<E> eventHandler) 从该网格中注销以前注册的事件处理程序。 |
EventDispatchChain | buildEventDispatchChain(EventDispatchChain tail) |
static class | MapBasedRowHeightFactory |
SpreadsheetColumn
公共方法
返回值类型 | 方法和说明 |
boolean | isFixed() 返回此列是否固定 |
void | setFixed(boolean fixed) 如果可能,请将此列固定在左侧,尽管建议您i的ColumnFixable()在尝试固定列之前先通知 |
void | setPrefWidth(double width) 设置此列的宽度 |
double | getWidth() 返回列的实际宽度 |
ReadOnlyDoublePRoperty | widthProperty() |
void | setMinWidth(double value) |
double | getMinWidth() |
DoubleProperty | minWidthProperty() |
DoubleProperty | maxWidthProperty() |
void | setMaxWidth(double value) |
double | getMaxWidth() |
void | setResizable(boolean b) 用户是否可以调整此列的大小 |
void | fitColumn() 如果该列可调整大小,它将为所有可见单元格计算最佳宽度 |
boolean | isColumnFixable() 指示此列是否可以固定 |
void | setFilter(Filter filter) |
Filter | getFilter() |
ObjectProperty | filterProperty() |
void | setText(String text) |
SpreadsheetCellBase
构造函数
SpreadsheetCellBase(int row, int column, int rowSpan, int columnSpan) 使用给定的配置构造一个SpreadsheetCell |
SpreadsheetCellBase(int row, int column, int rowSpan, int columnSpan, SpeadsheetCellType<?> type) 使用给定的配置构造一个SpreadsheetCell |
公共方法
返回值类型 | 方法和说明 |
boolean | match(Object value) 验证并设置当前单元格的值 |
void | setItem(Object value) 设置属性Item的值 |
Object | getItem() 返回单元格中包含的值 |
ObjectProperty<Object> | itemProperty() 表示此单元格石磊内部的当前设置值 |
boolean | isEditable() |
void | setEditable(boolean editable) 设置属性的值可编辑 |
boolean | isWrapText() |
boolean | isCellGraphic(boolean isBrowser) |
List<Object> | getOptionsForEditor() |
boolean | hasPopup() |
void | setHasPopup(boolean value) |
List<MenuItem> | getPopupItems() |
StringProperty | formatProperty() 该StringProperty格式为链接 |
String | getFormat() 返回此单元格的格式,如果未指定格式,则返回空字符串 |
void | setFormat(String format) 为此单元格设置新的格式 |
ReadOnlyStringProperty | textProperty() 返回值表示行是的字符串属性 |
String | getText() 返回当前用于显示的字符串表示形式 |
SpreadsheetCellType | getCellType() 返回SpreadsheetCellType此特定的单元格 |
int | getRow() 返回此单元格的行 |
int | getColumn() 返回此单元格的列 |
int | getRowSpan() 返回此单元格在行中的跨度,正常为1 |
void | setRowSpan(int rowSpan) 设置此单元格在行中的跨度 |
int | getColumnSpan() 返回此单元格在列中的跨度,正常为1 |
void | setColumnSpan(int columnSpan) 设置此单元格在列中的跨度 |
ObservableSet<String> | getStyleClass() 返回与此单元格关联的所有样式类的字符串列表 |
void | setStyle(String style) |
String | getStyle() |
StringProperty | styleProperty() |
ObjectProperty<Node> | graphicProperty() |
void | setGraphic(Node graphic) 设置此单元格的图形以在文本旁边显示 |
Node | getGraphic() 返回与此单元格关联的图形节点 |
Optional<String> | getTooltip() 返回提示信息 |
void | setTooltip(String tooltip) 为此单元格设置一个新的工具提示 |
void | activateCorner(CornerPosition position) |
void | deactivateCorner(CornerPosition position) |
boolean | isCornerActivated(CornerPosition position) |
EventDispatchChain | buildEventDispatchChain(EventDispatchChain tail) |
String | toString() |
boolean | equals(Object obj) |
int | hashCode() |
void | addEventHandler(EventType<Event> eventType, EventHandler<Event> eventHandler) |
void | removeEventHandler(EventType<Event> eventType, EventHandler<Event> eventHandler) |