本文整理汇总了Java中javafx.scene.control.TableColumn类的典型用法代码示例。如果您正苦于以下问题:Java TableColumn类的具体用法?Java TableColumn怎么用?Java TableColumn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TableColumn类属于javafx.scene.control包,在下文中一共展示了TableColumn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processChoiceBoxColumnName
import javafx.scene.control.TableColumn; //导入依赖的package包/类
private TableColumn processChoiceBoxColumnName(String name, JsonArray items){
TableColumn column = new TableColumn(name);
column.setCellValueFactory( p -> ((TableColumn.CellDataFeatures<Item, Object>)p).getValue().getStringProperty(name));
ObservableList list = FXCollections.observableArrayList();
if(items!=null) list.addAll(items.getList());
column.setCellFactory(ChoiceBoxTableCell.forTableColumn(list));
column.setOnEditCommit( t -> {
int index = ((TableColumn.CellEditEvent<Item, Object>) t).getTablePosition().getRow();
Item item = ((TableColumn.CellEditEvent<Item, Object>) t).getTableView().getItems().get(index);
item.setProperty(name,((TableColumn.CellEditEvent<Item, Object>) t).getNewValue());
});
columnMap.put(name, column);
return column;
}
示例2: TableSample
import javafx.scene.control.TableColumn; //导入依赖的package包/类
public TableSample() {
final ObservableList<Person> data = FXCollections.observableArrayList(
new Person("Jacob", "Smith", "[email protected]" ),
new Person("Isabella", "Johnson", "[email protected]" ),
new Person("Ethan", "Williams", "[email protected]" ),
new Person("Emma", "Jones", "[email protected]" ),
new Person("Michael", "Brown", "[email protected]" )
);
TableColumn firstNameCol = new TableColumn();
firstNameCol.setText("First");
firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName"));
TableColumn lastNameCol = new TableColumn();
lastNameCol.setText("Last");
lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName"));
TableColumn emailCol = new TableColumn();
emailCol.setText("Email");
emailCol.setMinWidth(200);
emailCol.setCellValueFactory(new PropertyValueFactory("email"));
TableView tableView = new TableView();
tableView.setItems(data);
tableView.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
getChildren().add(tableView);
}
示例3: VarsPanel
import javafx.scene.control.TableColumn; //导入依赖的package包/类
public VarsPanel(AppSession session) {
this.session = session;
table = new TableView();
table.setPrefWidth(300);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
setCenter(table);
TableColumn nameCol = new TableColumn("Variable");
nameCol.setMinWidth(120);
nameCol.setMaxWidth(250);
nameCol.setCellValueFactory(new PropertyValueFactory("name"));
nameCol.setCellFactory(c -> new StringTooltipCell());
TableColumn typeCol = new TableColumn("Type");
typeCol.setMinWidth(45);
typeCol.setMaxWidth(60);
typeCol.setCellValueFactory(new PropertyValueFactory("type"));
TableColumn<Var, ScriptValue> valueCol = new TableColumn("Value");
valueCol.setCellValueFactory(c -> new ReadOnlyObjectWrapper(c.getValue().getValue()));
valueCol.setCellFactory(c -> new VarValueCell());
table.getColumns().addAll(nameCol, typeCol, valueCol);
table.setItems(session.getVars());
table.setRowFactory(tv -> {
TableRow<Var> row = new TableRow<>();
row.setOnMouseClicked(e -> {
if (e.getClickCount() == 2 && !row.isEmpty()) {
Var var = row.getItem();
session.logVar(var);
}
});
return row ;
});
}
示例4: createOrganizationTable
import javafx.scene.control.TableColumn; //导入依赖的package包/类
private TableView<OrganizationView> createOrganizationTable(ObservableList<OrganizationView> orgas) {
TableView<OrganizationView> result = new TableView<>(orgas);
TableColumn<OrganizationView, String> name = new TableColumn<>("Name");
TableColumn<OrganizationView, String> owned = new TableColumn<>("Owned");
TableColumn<OrganizationView, Integer> serverCount = new TableColumn<>("Servers");
name.setCellValueFactory(new PropertyValueFactory<>("name"));
serverCount.setCellValueFactory(new PropertyValueFactory<>("serverCount"));
owned.setCellValueFactory(new PropertyValueFactory<>("isOwned"));
serverCount.setMinWidth(70);
serverCount.setMaxWidth(70);
owned.setMaxWidth(70);
owned.setMinWidth(70);
result.getColumns().add(name);
result.getColumns().add(serverCount);
result.getColumns().add(owned);
return result;
}
示例5: UkeireTableView
import javafx.scene.control.TableColumn; //导入依赖的package包/类
public UkeireTableView() {
super();
TableColumn<Ukeire, String> candidateHaiStringColmun = new TableColumn<>("選");
TableColumn<Ukeire, String> syantenColmun = new TableColumn<>("聴");
TableColumn<Ukeire, String> infoColmun = new TableColumn<>("枚数");
TableColumn<Ukeire, String> ukeireHaiStringsColmun = new TableColumn<>("受入牌");
candidateHaiStringColmun.setCellValueFactory(e -> new SimpleStringProperty(HaiString.getHaiStringByIndex(e.getValue().getCandidateIndex())));
syantenColmun.setCellValueFactory(e -> new SimpleStringProperty(e.getValue().getSyanten() == -1 ? "-" : String.valueOf(e.getValue().getSyanten())));
infoColmun.setCellValueFactory(e -> new SimpleStringProperty(e.getValue().getSize() + "種" + e.getValue().getSum() + "牌"));
ukeireHaiStringsColmun.setCellValueFactory(e -> new SimpleStringProperty(e.getValue().getUkeireIndices().stream().map(HaiString::getHaiStringByIndex).collect(Collectors.joining())));
candidateHaiStringColmun.prefWidthProperty().bind(widthProperty().multiply(0.15));
syantenColmun.prefWidthProperty().bind(widthProperty().multiply(0.13));
infoColmun.prefWidthProperty().bind(widthProperty().multiply(0.3));
ukeireHaiStringsColmun.prefWidthProperty().bind(widthProperty().multiply(0.41));
getColumns().addAll(candidateHaiStringColmun, syantenColmun, infoColmun, ukeireHaiStringsColmun);
}
示例6: createWrappableTableCell
import javafx.scene.control.TableColumn; //导入依赖的package包/类
/**
* Creates a wrapped table cell.
*
* @param column the table column in which the cell resides
* @return a TableCell with the text wrapped inside
*/
private TableCell<Annotation, String> createWrappableTableCell(final TableColumn<Annotation, String> column) {
return new TableCell<Annotation, String>() {
@Override
protected void updateItem(final String item, final boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setGraphic(null);
return;
}
final Text text = new Text(item);
text.setWrappingWidth(column.getWidth() - TEXT_PADDING);
setPrefHeight(text.getLayoutBounds().getHeight());
setGraphic(text);
}
};
}
示例7: wrappableTableCell
import javafx.scene.control.TableColumn; //导入依赖的package包/类
/**
* Create a table cell that wraps the text inside.
*
* @param param the table column
* @return a table cell that wraps the text inside
*/
TableCell<Annotation, String> wrappableTableCell(final TableColumn<Annotation, String> param) {
return new TableCell<Annotation, String>() {
@Override
protected void updateItem(final String item, final boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setGraphic(null);
return;
}
final Text text = new Text(item);
text.setWrappingWidth(param.getWidth());
setPrefHeight(text.getLayoutBounds().getHeight());
setGraphic(text);
}
};
}
示例8: tableColumns
import javafx.scene.control.TableColumn; //导入依赖的package包/类
public static void tableColumns(final Visitor v, List<? extends TableColumn<?, ?>> addedSubList) {
for(int i = 0; i < addedSubList.size(); i++){
final TableColumn<?,?> col = addedSubList.get(i);
col.setCellFactory(new DnDTableCellFactory(v, col.getCellFactory()));
col.cellFactoryProperty().addListener(new ChangeListener<Callback>() {
@Override
public void changed(ObservableValue<? extends Callback> observable, Callback oldValue,
Callback newValue) {
if(!(newValue instanceof DnDTableCellFactory)){
col.setCellFactory(new DnDTableCellFactory(v, col.getCellFactory()));
}
}
});
}
}
示例9: getVisibleCellAt
import javafx.scene.control.TableColumn; //导入依赖的package包/类
public TableCell<?, ?> getVisibleCellAt(TableView<?> tableView, int row, int column) {
Set<Node> lookupAll = getTableCells(tableView);
TableCell<?, ?> cell = null;
for (Node node : lookupAll) {
TableCell<?, ?> cell1 = (TableCell<?, ?>) node;
TableRow<?> tableRow = cell1.getTableRow();
TableColumn<?, ?> tableColumn = cell1.getTableColumn();
if (tableRow.getIndex() == row && tableColumn == tableView.getColumns().get(column)) {
cell = cell1;
break;
}
}
if (cell != null) {
return cell;
}
return null;
}
示例10: selectCells
import javafx.scene.control.TableColumn; //导入依赖的package包/类
@SuppressWarnings("unchecked") public void selectCells(TableView<?> tableView, String value) {
@SuppressWarnings("rawtypes")
TableViewSelectionModel selectionModel = tableView.getSelectionModel();
selectionModel.clearSelection();
JSONObject cells = new JSONObject(value);
JSONArray object = (JSONArray) cells.get("cells");
for (int i = 0; i < object.length(); i++) {
JSONArray jsonArray = object.getJSONArray(i);
int rowIndex = Integer.parseInt(jsonArray.getString(0));
int columnIndex = getColumnIndex(jsonArray.getString(1));
@SuppressWarnings("rawtypes")
TableColumn column = tableView.getColumns().get(columnIndex);
if (getVisibleCellAt(tableView, rowIndex, columnIndex) == null) {
tableView.scrollTo(rowIndex);
tableView.scrollToColumn(column);
}
selectionModel.select(rowIndex, column);
}
}
示例11: TableScrollSample
import javafx.scene.control.TableColumn; //导入依赖的package包/类
public TableScrollSample() {
final ObservableList<Person> data = FXCollections.observableArrayList(
new Person("Jacob", "Smith", "[email protected]"),
new Person("Isabella", "Johnson", "[email protected]"),
new Person("Ethan", "Williams", "[email protected]"),
new Person("Emma", "Jones", "[email protected]"), new Person("Michael", "Brown", "[email protected]"));
TableColumn firstNameCol = new TableColumn();
firstNameCol.setText("First");
firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName"));
TableColumn lastNameCol = new TableColumn();
lastNameCol.setText("Last");
lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName"));
TableColumn emailCol = new TableColumn();
emailCol.setText("Email");
emailCol.setMinWidth(200);
emailCol.setCellValueFactory(new PropertyValueFactory("email"));
TableView tableView = new TableView();
tableView.setItems(data);
ObservableList items = tableView.getItems();
for (int i = 0; i < 10; i++)
items.add(new Person("Name" + i, "Last" + i, "Email " + i));
tableView.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
getChildren().add(tableView);
}
示例12: select
import javafx.scene.control.TableColumn; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void select() {
TableView<?> tableView = (TableView<?>) getPrimaryStage().getScene().getRoot().lookup(".table-view");
LoggingRecorder lr = new LoggingRecorder();
Platform.runLater(() -> {
Point2D point = getPoint(tableView, 2, 1);
ComboBoxTableCell cell = (ComboBoxTableCell) getCellAt(tableView, 1, 2);
RFXTableView rfxTableView = new RFXTableView(tableView, null, point, lr);
rfxTableView.focusGained(null);
cell.startEdit();
tableView.edit(1, (TableColumn) tableView.getColumns().get(2));
Person person = (Person) tableView.getItems().get(1);
person.setLastName("Jones");
cell.commitEdit("Jones");
rfxTableView.focusLost(null);
});
List<Recording> recordings = lr.waitAndGetRecordings(1);
Recording recording = recordings.get(0);
AssertJUnit.assertEquals("recordSelect", recording.getCall());
AssertJUnit.assertEquals("Jones", recording.getParameters()[0]);
}
示例13: selectEditable
import javafx.scene.control.TableColumn; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void selectEditable() {
TableView<?> tableView = (TableView<?>) getPrimaryStage().getScene().getRoot().lookup(".table-view");
LoggingRecorder lr = new LoggingRecorder();
Platform.runLater(() -> {
Point2D point = getPoint(tableView, 2, 1);
ComboBoxTableCell cell = (ComboBoxTableCell) getCellAt(tableView, 1, 2);
cell.setEditable(true);
RFXTableView rfxTableView = new RFXTableView(tableView, null, point, lr);
rfxTableView.focusGained(null);
cell.startEdit();
tableView.edit(1, (TableColumn) tableView.getColumns().get(2));
Person person = (Person) tableView.getItems().get(1);
person.setLastName("Jones");
cell.commitEdit("Jones");
rfxTableView.focusLost(null);
});
List<Recording> recordings = lr.waitAndGetRecordings(1);
Recording recording = recordings.get(0);
AssertJUnit.assertEquals("recordSelect", recording.getCall());
AssertJUnit.assertEquals("Jones", recording.getParameters()[0]);
}
示例14: selectACell
import javafx.scene.control.TableColumn; //导入依赖的package包/类
@SuppressWarnings("unchecked") @Test public void selectACell() {
TableView<?> tableView = (TableView<?>) getPrimaryStage().getScene().getRoot().lookup(".table-view");
LoggingRecorder lr = new LoggingRecorder();
Platform.runLater(() -> {
tableView.getSelectionModel().setCellSelectionEnabled(true);
Point2D point = getPoint(tableView, 1, 1);
RFXTableView rfxTableView = new RFXTableView(tableView, null, point, lr);
rfxTableView.focusGained(null);
@SuppressWarnings("rawtypes")
TableColumn column = getTableColumnAt(tableView, 1);
tableView.getSelectionModel().select(1, column);
rfxTableView.focusLost(null);
});
List<Recording> recordings = lr.waitAndGetRecordings(1);
Recording recording = recordings.get(0);
AssertJUnit.assertEquals("recordSelect", recording.getCall());
AssertJUnit.assertEquals("{\"cells\":[[\"1\",\"Last\"]]}", recording.getParameters()[0]);
}
示例15: selectCell
import javafx.scene.control.TableColumn; //导入依赖的package包/类
@SuppressWarnings("unchecked") @Test public void selectCell() {
TableView<?> tableView = (TableView<?>) getPrimaryStage().getScene().getRoot().lookup(".table-view");
LoggingRecorder lr = new LoggingRecorder();
Platform.runLater(() -> {
tableView.getSelectionModel().setCellSelectionEnabled(true);
Point2D point = getPoint(tableView, 1, 1);
RFXTableView rfxTableView = new RFXTableView(tableView, null, point, lr);
rfxTableView.focusGained(null);
@SuppressWarnings("rawtypes")
TableColumn column = getTableColumnAt(tableView, 1);
tableView.getSelectionModel().select(1, column);
rfxTableView.focusLost(null);
});
List<Recording> recordings = lr.waitAndGetRecordings(1);
Recording recording = recordings.get(0);
AssertJUnit.assertEquals("recordSelect", recording.getCall());
AssertJUnit.assertEquals("{\"cells\":[[\"1\",\"Last\"]]}", recording.getParameters()[0]);
}