Java Code Examples for javafx.scene.control.TableColumn#setPrefWidth()

The following examples show how to use javafx.scene.control.TableColumn#setPrefWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PVList.java    From phoebus with Eclipse Public License 1.0 7 votes vote down vote up
private void createTableColumns()
{
    final TableColumn<PVInfo, Boolean> conn_col = new TableColumn<>(Messages.PVListTblConnected);
    conn_col.setCellFactory(col -> new ConnectedCell());
    conn_col.setCellValueFactory(cell -> cell.getValue().connected);
    conn_col.setMinWidth(20.0);
    conn_col.setPrefWidth(300.0);
    conn_col.setMaxWidth(500.0);
    table.getColumns().add(conn_col);

    final TableColumn<PVInfo, String> name_col = new TableColumn<>(Messages.PVListTblPVName);
    name_col.setCellValueFactory(cell -> cell.getValue().name);
    table.getColumns().add(name_col);

    final TableColumn<PVInfo, Number> ref_col = new TableColumn<>(Messages.PVListTblReferences);
    ref_col.setCellValueFactory(cell -> cell.getValue().references);
    ref_col.setMaxWidth(500.0);
    table.getColumns().add(ref_col);
}
 
Example 2
Source File: DatePickerCellDemo.java    From tornadofx-controls with Apache License 2.0 6 votes vote down vote up
public void start(Stage stage) throws Exception {
    TableView<Customer> tableView = new TableView<>(FXCollections.observableArrayList(Customer.createSample(555)));
    tableView.setEditable(true);

    TableColumn<Customer, String> username = new TableColumn<>("Username");
    username.setCellValueFactory(param -> param.getValue().usernameProperty());

    TableColumn<Customer, LocalDate> registered = new TableColumn<>("Registered");
    registered.setCellValueFactory(param -> param.getValue().registeredProperty());
    registered.setCellFactory(DatePickerTableCell.forTableColumn());
    registered.setPrefWidth(150);

    tableView.getColumns().addAll(username, registered);

    stage.setScene(new Scene(tableView, 800, 600));
    stage.show();
}
 
Example 3
Source File: IndexController.java    From WIFIProbe with Apache License 2.0 5 votes vote down vote up
private void initProcessTable() {
    ObservableList<TableColumn<Process, ?>> processCols = processTable.getColumns();
    processCols.get(0).setCellValueFactory(new PropertyValueFactory<>("status"));
    TableColumn<Process,Double> processCol = new TableColumn<>("进度");
    processCol.setPrefWidth(475);
    processCol.setCellValueFactory(new PropertyValueFactory<>("progress"));
    processCol.setCellFactory(ProgressBarTableCell.forTableColumn());
    processCols.set(1,processCol);
    processCols.get(2).setCellValueFactory(new PropertyValueFactory<>("percent"));
    processCols.get(3).setCellValueFactory(new PropertyValueFactory<>("lastUpdate"));
}
 
Example 4
Source File: TrainingExerciseBase.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds a column to the shot timer table. The <tt>name</tt> is used to
 * reference this column for the purposes of setting text and cleaning up.
 * 
 * @param name
 *            both the text that will appear for name of the column and the
 *            name used to reference this column whenever it needs to be
 *            looked up
 * @param width
 *            the width of the new column
 * 
 * @since 1.3
 */
public void addShotTimerColumn(String name, int width) {
	final TableColumn<ShotEntry, String> newCol = new TableColumn<>(name);
	newCol.setPrefWidth(width);
	newCol.setCellValueFactory(new Callback<CellDataFeatures<ShotEntry, String>, ObservableValue<String>>() {
		@Override
		public ObservableValue<String> call(CellDataFeatures<ShotEntry, String> p) {
			return new SimpleStringProperty(p.getValue().getExerciseValue(name));
		}
	});

	exerciseColumns.put(name, newCol);
	shotTimerTable.getColumns().add(newCol);
}
 
Example 5
Source File: FilterGridController.java    From VocabHunter with Apache License 2.0 5 votes vote down vote up
private TableColumn<GridLine, GridCell> buildColumn(final FilterGridModel filterModel, final int index) {
    TableColumn<GridLine, GridCell> column = new TableColumn<>(columnNameTool.columnName(index));

    column.setSortable(false);
    column.setCellValueFactory(features -> extractValue(features, index));
    column.setCellFactory(c -> new FilterGridWordTableCell(filterModel.getColumnSelections().get(index)));
    if (isScrollableColumnList(filterModel)) {
        column.setPrefWidth(PREFERRED_COLUMN_WIDTH);
    }

    return column;
}
 
Example 6
Source File: ScenarioEditorController.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
private void createColumns(TableView<Scenario> tableView) {
    TableColumn<Scenario, String> recipeNameCol = new TableColumn<>("Settlement");
    recipeNameCol.setCellValueFactory(new PropertyValueFactory("name"));
    recipeNameCol.setPrefWidth( 100 );

    TableColumn<Scenario, String> classNameCol = new TableColumn<>("Template");
    classNameCol.setCellValueFactory(new PropertyValueFactory("className"));
    classNameCol.setPrefWidth( 100 );

    TableColumn<Scenario, String> descriptionCol = new TableColumn<>("Description");
    descriptionCol.setCellValueFactory(new PropertyValueFactory("description"));
    descriptionCol.setPrefWidth(tableView.getPrefWidth() - 200 );
    tableView.getColumns().setAll(recipeNameCol, classNameCol, descriptionCol);
}
 
Example 7
Source File: ConsoleOutputControl.java    From chvote-1-0 with GNU Affero General Public License v3.0 5 votes vote down vote up
@FXML
public void initialize() throws IOException {
    TableColumn<LogMessage, GlyphIcon> logLevelColumn = new TableColumn<>();
    logLevelColumn.setCellValueFactory(new PropertyValueFactory<>("glyphIcon"));
    logLevelColumn.setMinWidth(50.0);
    logLevelColumn.setPrefWidth(50.0);
    logLevelColumn.setMaxWidth(50.0);

    TableColumn<LogMessage, String> messageColumn = new TableColumn<>();
    messageColumn.setCellValueFactory(new PropertyValueFactory<>("message"));

    logTable.setItems(logMessages);
    ObservableList<TableColumn<LogMessage, ?>> tableColumns = logTable.getColumns();
    tableColumns.add(logLevelColumn);
    tableColumns.add(messageColumn);

    logTable.setEditable(false);
    // Prevent cell selection
    logTable.addEventFilter(MouseEvent.ANY, Event::consume);
    // Do not display a placeholder
    logTable.setPlaceholder(new Label(""));
    // Hide the header row
    logTable.widthProperty().addListener((observable, oldValue, newValue) -> {
        Pane header = (Pane) logTable.lookup("TableHeaderRow");
        if (header.isVisible()) {
            header.setMaxHeight(0);
            header.setMinHeight(0);
            header.setPrefHeight(0);
            header.setVisible(false);
        }
    });
    progressBar.setProgress(0f);
}
 
Example 8
Source File: DefaultTable.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
protected void addColumnNumber(String heading, int width, String propertyName)
{
  TableColumn<T, Number> column = new TableColumn(heading);
  column.setPrefWidth(width);
  column.setCellValueFactory(new PropertyValueFactory(propertyName));
  getColumns().add(column);
  column.setStyle("-fx-alignment: CENTER-RIGHT;");
}
 
Example 9
Source File: DefaultTable.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
protected void addColumnString(String heading, int width, Justification justification, String propertyName)
{
  TableColumn<T, String> column = new TableColumn(heading);
  column.setPrefWidth(width);
  column.setCellValueFactory(new PropertyValueFactory(propertyName));
  getColumns().add(column);
  
  if (justification == Justification.CENTER) {
    column.setStyle("-fx-alignment: CENTER;");
  }
}
 
Example 10
Source File: IndexController.java    From WIFIProbe with Apache License 2.0 5 votes vote down vote up
private void initStatusTable() {
    ObservableList<TableColumn<ProbeStatus, ?>> statusColumns = statusTable.getColumns();
    statusColumns.get(0).setCellValueFactory(new PropertyValueFactory<>("id"));
    statusColumns.get(1).setCellValueFactory(new PropertyValueFactory<>("status"));
    statusColumns.get(2).setCellValueFactory(new PropertyValueFactory<>("ip"));
    TableColumn<ProbeStatus,String> actionCol = new TableColumn<>("操作");
    actionCol.setPrefWidth(250);
    actionCol.setCellValueFactory(new PropertyValueFactory<>("DUMMY"));
    actionCol.setCellFactory(param -> new TableCell<ProbeStatus,String>() {
        final Button btn = new Button("管理");
        @Override
        public void updateItem(String item, boolean empty) {
            super.updateItem(item, empty);
            if (empty) {
                setGraphic(null);
                setText(null);
            } else {
                btn.setOnAction(event -> {
                    ProbeStatus probeStatus = getTableView().getItems().get(getIndex());
                    try {
                        URI uri = new URI(probeStatus.getIp());
                        Desktop.getDesktop().browse(uri);
                    } catch (URISyntaxException | IOException e) {
                        e.printStackTrace();
                    }
                });
                setGraphic(btn);
                setText(null);
            }
        }
    });
    statusColumns.add(actionCol);
}
 
Example 11
Source File: ConnectionView.java    From erlyberly with GNU General Public License v3.0 5 votes vote down vote up
private TableColumn<KnownNode, Boolean> newNodeRunningColumn(String colText, String colPropertyName, double colWidth) {
    TableColumn<KnownNode, Boolean> column;
    column = new TableColumn<>(colText);
    column.setCellValueFactory( node -> { return node.getValue().runningProperty(); });
    column.setCellFactory( tc -> new CheckBoxTableCell<>());
    column.setPrefWidth(colWidth);
    return column;
}
 
Example 12
Source File: CTimePeriodField.java    From Open-Lowcode with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public TableColumn<ObjectTableRow, TimePeriod> getTableColumn(
		PageActionManager pageactionmanager,
		boolean largedisplay,
		int preferedrowheight,
		String actionkeyforupdate) {
	TableColumn<
			ObjectTableRow, TimePeriod> thiscolumn = new TableColumn<ObjectTableRow, TimePeriod>(this.getLabel());
	if (actionkeyforupdate != null) {
		thiscolumn.setEditable(true);
		thiscolumn.setOnEditCommit(new TableColumnOnEditCommit(this));
	} else {
		thiscolumn.setEditable(false);
	}

	int length = 15 * 7;
	if (length > 300)
		length = 300;

	double pixellength = ((new Text(this.label)).getBoundsInLocal().getWidth() + 10) * 1.05;

	int pixellengthi = (int) pixellength;
	thiscolumn.setMinWidth(pixellengthi);
	thiscolumn.setPrefWidth(pixellengthi);
	thiscolumn.setCellValueFactory(new TableCellValueFactory(this));

	thiscolumn.setCellFactory(new TableCellFactory(helper, periodtype));

	return thiscolumn;
}
 
Example 13
Source File: AlarmTableUI.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private TableView<AlarmInfoRow> createTable(final ObservableList<AlarmInfoRow> rows,
                                            final boolean active)
{
    final SortedList<AlarmInfoRow> sorted = new SortedList<>(rows);
    final TableView<AlarmInfoRow> table = new TableView<>(sorted);

    // Ensure that the sorted rows are always updated as the column sorting
    // of the TableView is changed by the user clicking on table headers.
    sorted.comparatorProperty().bind(table.comparatorProperty());

    TableColumn<AlarmInfoRow, SeverityLevel> sevcol = new TableColumn<>(/* Icon */);
    sevcol.setPrefWidth(25);
    sevcol.setReorderable(false);
    sevcol.setResizable(false);
    sevcol.setCellValueFactory(cell -> cell.getValue().severity);
    sevcol.setCellFactory(c -> new SeverityIconCell());
    table.getColumns().add(sevcol);

    final TableColumn<AlarmInfoRow, String> pv_col = new TableColumn<>("PV");
    pv_col.setPrefWidth(240);
    pv_col.setReorderable(false);
    pv_col.setCellValueFactory(cell -> cell.getValue().pv);
    pv_col.setCellFactory(c -> new DragPVCell());
    pv_col.setComparator(CompareNatural.INSTANCE);
    table.getColumns().add(pv_col);

    TableColumn<AlarmInfoRow, String> col = new TableColumn<>("Description");
    col.setPrefWidth(400);
    col.setReorderable(false);
    col.setCellValueFactory(cell -> cell.getValue().description);
    col.setCellFactory(c -> new DragPVCell());
    col.setComparator(CompareNatural.INSTANCE);
    table.getColumns().add(col);

    sevcol = new TableColumn<>("Alarm Severity");
    sevcol.setPrefWidth(130);
    sevcol.setReorderable(false);
    sevcol.setCellValueFactory(cell -> cell.getValue().severity);
    sevcol.setCellFactory(c -> new SeverityLevelCell());
    table.getColumns().add(sevcol);

    col = new TableColumn<>("Alarm Status");
    col.setPrefWidth(130);
    col.setReorderable(false);
    col.setCellValueFactory(cell -> cell.getValue().status);
    col.setCellFactory(c -> new DragPVCell());
    table.getColumns().add(col);

    TableColumn<AlarmInfoRow, Instant> timecol = new TableColumn<>("Alarm Time");
    timecol.setPrefWidth(200);
    timecol.setReorderable(false);
    timecol.setCellValueFactory(cell -> cell.getValue().time);
    timecol.setCellFactory(c -> new TimeCell());
    table.getColumns().add(timecol);

    col = new TableColumn<>("Alarm Value");
    col.setPrefWidth(100);
    col.setReorderable(false);
    col.setCellValueFactory(cell -> cell.getValue().value);
    col.setCellFactory(c -> new DragPVCell());
    table.getColumns().add(col);

    sevcol = new TableColumn<>("PV Severity");
    sevcol.setPrefWidth(130);
    sevcol.setReorderable(false);
    sevcol.setCellValueFactory(cell -> cell.getValue().pv_severity);
    sevcol.setCellFactory(c -> new SeverityLevelCell());
    table.getColumns().add(sevcol);

    col = new TableColumn<>("PV Status");
    col.setPrefWidth(130);
    col.setReorderable(false);
    col.setCellValueFactory(cell -> cell.getValue().pv_status);
    col.setCellFactory(c -> new DragPVCell());
    table.getColumns().add(col);

    // Initially, sort on PV name
    // - restore(Memento) might change that
    table.getSortOrder().setAll(List.of(pv_col));
    pv_col.setSortType(SortType.ASCENDING);

    table.setPlaceholder(new Label(active ? "No active alarms" : "No acknowledged alarms"));
    table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    createContextMenu(table, active);

    // Double-click to acknowledge or un-acknowledge
    table.setRowFactory(tv ->
    {
        final TableRow<AlarmInfoRow> row = new TableRow<>();
        row.setOnMouseClicked(event ->
        {
            if (event.getClickCount() == 2  &&  !row.isEmpty())
                JobManager.schedule("ack", monitor ->  client.acknowledge(row.getItem().item, active));
        });
        return row;
    });

    return table;
}
 
Example 14
Source File: DbgTraceView.java    From erlyberly with GNU General Public License v3.0 4 votes vote down vote up
private void configureColumnWidth(String widthProperty, TableColumn<TraceLog, ?> functionNameColumn) {
    functionNameColumn.setPrefWidth(PrefBind.getOrDefaultDouble(widthProperty, functionNameColumn.getPrefWidth()));
    functionNameColumn.widthProperty().addListener((o, ov, nv) -> {
        PrefBind.set(widthProperty, nv);
    });
}
 
Example 15
Source File: ConnectionView.java    From erlyberly with GNU General Public License v3.0 4 votes vote down vote up
private TableColumn<KnownNode, ?> newColumn(String colText, String colPropertyName, double colWidth) {
    TableColumn<KnownNode, String> col = newColumn(colText, colPropertyName);
    col.setPrefWidth(colWidth);
    return col;
}
 
Example 16
Source File: PVTable.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private void createTableColumns()
{
    // Selected column
    final TableColumn<TableItemProxy, Boolean> sel_col = new TableColumn<>(Messages.Selected);
    sel_col.setCellValueFactory(cell -> cell.getValue().selected);
    sel_col.setCellFactory(column -> new BooleanTableCell());
    table.getColumns().add(sel_col);

    // PV Name
    TableColumn<TableItemProxy, String> col = new TableColumn<>(Messages.PV);
    col.setPrefWidth(250);
    col.setCellValueFactory(cell_data_features -> cell_data_features.getValue().name);
    col.setCellFactory(column -> new PVNameTableCell());
    col.setOnEditCommit(event ->
    {
        final String new_name = event.getNewValue().trim();
        final TableItemProxy proxy = event.getRowValue();
        if (proxy == TableItemProxy.NEW_ITEM)
        {
            if (!new_name.isEmpty())
                model.addItem(new_name);
            // else: No name entered, do nothing
        }
        else
        {
            // Set name, even if empty, assuming user wants to continue
            // editing the existing row.
            // To remove row, use context menu.
            proxy.getItem().updateName(new_name);
            proxy.update(proxy.getItem());
            // Content of model changed.
            // Triggers full table update.
            model.fireModelChange();
        }
    });
    // Use natural order for PV name
    col.setComparator(CompareNatural.INSTANCE);
    table.getColumns().add(col);

    // Description
    if (Settings.show_description)
    {
        col = new TableColumn<>(Messages.Description);
        col.setCellValueFactory(cell -> cell.getValue().desc_value);
        table.getColumns().add(col);
    }

    // Time Stamp
    col = new TableColumn<>(Messages.Time);
    col.setCellValueFactory(cell ->  cell.getValue().time);
    table.getColumns().add(col);

    // Editable value
    col = new TableColumn<>(Messages.Value);
    col.setCellValueFactory(cell -> cell.getValue().value);
    col.setCellFactory(column -> new ValueTableCell(model));
    col.setOnEditCommit(event ->
    {
        event.getRowValue().getItem().setValue(event.getNewValue());
        // Since updates were suppressed, refresh table
        model.performPendingUpdates();
    });
    col.setOnEditCancel(event ->
    {
        // Since updates were suppressed, refresh table
        model.performPendingUpdates();
    });
    // Use natural order for value
    col.setComparator(CompareNatural.INSTANCE);
    table.getColumns().add(col);

    // Alarm
    col = new TableColumn<>(Messages.Alarm);
    col.setCellValueFactory(cell -> cell.getValue().alarm);
    col.setCellFactory(column -> new AlarmTableCell());
    table.getColumns().add(col);

    // Saved value
    col = new TableColumn<>(Messages.Saved);
    col.setCellValueFactory(cell -> cell.getValue().saved);
    // Use natural order for saved value
    col.setComparator(CompareNatural.INSTANCE);
    saved_value_col = col;
    table.getColumns().add(col);

    // Saved value's timestamp
    col = new TableColumn<>(Messages.Saved_Value_TimeStamp);
    col.setCellValueFactory(cell -> cell.getValue().time_saved);
    saved_time_col = col;
    table.getColumns().add(col);

    // Completion checkbox
    final TableColumn<TableItemProxy, Boolean> compl_col = new TableColumn<>(Messages.Completion);
    compl_col.setCellValueFactory(cell -> cell.getValue().use_completion);
    compl_col.setCellFactory(column -> new BooleanTableCell());
    completion_col = compl_col;
    table.getColumns().add(compl_col);
}
 
Example 17
Source File: ImagePanel.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
private void createRightPane() {
    annotationTable.getSelectionModel().getSelectedItems().addListener(new ListChangeListener<Annotation>() {
        @Override
        public void onChanged(javafx.collections.ListChangeListener.Change<? extends Annotation> c) {
            drawGraphics();
            markSelected();
        }
    });
    annotationTable.setEditable(edit);
    annotationTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    annotationTable.addEventHandler(KeyEvent.KEY_PRESSED, (event) -> {
        if (event.getCode() == KeyCode.DELETE || event.getCode() == KeyCode.BACK_SPACE) {
            removeAnnotation();
        }
    });
    TableColumn<Annotation, String> messageColumn = new TableColumn<Annotation, String>("Annotation");
    PropertyValueFactory<Annotation, String> value = new PropertyValueFactory<>("text");
    messageColumn.setCellValueFactory(value);
    messageColumn.setCellFactory(new Callback<TableColumn<Annotation, String>, TableCell<Annotation, String>>() {
        @Override
        public TableCell<Annotation, String> call(TableColumn<Annotation, String> param) {
            return new TextAreaTableCell();
        }
    });
    messageColumn.prefWidthProperty().bind(annotationTable.widthProperty().subtract(25));

    TableColumn<Annotation, String> numCol = new TableColumn<>("#");
    numCol.setCellFactory(new Callback<TableColumn<Annotation, String>, TableCell<Annotation, String>>() {
        @Override
        public TableCell<Annotation, String> call(TableColumn<Annotation, String> p) {
            return new TableCell() {
                @Override
                protected void updateItem(Object item, boolean empty) {
                    super.updateItem(item, empty);
                    setGraphic(null);
                    setText(empty ? null : getIndex() + 1 + "");
                }
            };
        }
    });
    numCol.setPrefWidth(25);

    annotationTable.setItems(annotations);
    annotationTable.getColumns().addAll(numCol, messageColumn);
}
 
Example 18
Source File: MainAction.java    From DevToolBox with GNU Lesser General Public License v2.1 4 votes vote down vote up
private TableColumn getColumn(String name, String key, double width) {
    TableColumn attr = new TableColumn(name);
    attr.setCellValueFactory(new MapValueFactory<>(key));
    attr.setPrefWidth(width);
    return attr;
}
 
Example 19
Source File: MonitorController.java    From OEE-Designer with MIT License 4 votes vote down vote up
private void createNotificationTable() {
	// collector host
	TableColumn<CollectorNotification, String> tcCollector = new TableColumn<>(
			MonitorLocalizer.instance().getLangString("collector"));
	tvNotifications.getColumns().add(tcCollector);

	TableColumn<CollectorNotification, String> tcCollectorHost = new TableColumn<>(
			MonitorLocalizer.instance().getLangString("host"));
	tcCollectorHost.setPrefWidth(150);
	tcCollectorHost.setCellValueFactory(cellDataFeatures -> {
		return new SimpleStringProperty(cellDataFeatures.getValue().getCollectorHost());
	});
	tcCollector.getColumns().add(tcCollectorHost);

	// collector IP
	TableColumn<CollectorNotification, String> tcCollectorIp = new TableColumn<>(
			MonitorLocalizer.instance().getLangString("ip.address"));
	tcCollectorIp.setPrefWidth(150);
	tcCollectorIp.setCellValueFactory(cellDataFeatures -> {
		return new SimpleStringProperty(cellDataFeatures.getValue().getCollectorIpAddress());
	});
	tcCollector.getColumns().add(tcCollectorIp);

	// timestamp
	TableColumn<CollectorNotification, String> tcTimestamp = new TableColumn<>(
			MonitorLocalizer.instance().getLangString("timestamp"));
	tcTimestamp.setPrefWidth(250);
	tcTimestamp.setCellValueFactory(cellDataFeatures -> {
		String timestamp = cellDataFeatures.getValue().getTimestamp();
		OffsetDateTime odt = DomainUtils.offsetDateTimeFromString(timestamp, DomainUtils.OFFSET_DATE_TIME_8601);
		return new SimpleStringProperty(
				DomainUtils.offsetDateTimeToString(odt, DomainUtils.OFFSET_DATE_TIME_PATTERN));
	});
	tvNotifications.getColumns().add(tcTimestamp);

	// severity
	TableColumn<CollectorNotification, Text> tcSeverity = new TableColumn<>(
			MonitorLocalizer.instance().getLangString("severity"));
	tcSeverity.setPrefWidth(100);
	tcSeverity.setCellValueFactory(cellDataFeatures -> {
		NotificationSeverity severity = cellDataFeatures.getValue().getSeverity();
		Text text = new Text(severity.toString());
		text.setFill(severity.getColor());
		return new SimpleObjectProperty<Text>(text);
	});

	tvNotifications.getColumns().add(tcSeverity);

	// message
	TableColumn<CollectorNotification, String> tcText = new TableColumn<>(
			MonitorLocalizer.instance().getLangString("message"));
	tcText.setPrefWidth(600);
	tcText.setCellValueFactory(cellDataFeatures -> {
		return new SimpleStringProperty(cellDataFeatures.getValue().getText());
	});
	tvNotifications.getColumns().add(tcText);
}
 
Example 20
Source File: BattleOfDecksResultView.java    From metastone with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public BattleOfDecksResultView() {
	FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/BattleOfDecksResultView.fxml"));
	fxmlLoader.setRoot(this);
	fxmlLoader.setController(this);

	try {
		fxmlLoader.load();
	} catch (IOException exception) {
		throw new RuntimeException(exception);
	}

	TableColumn<BattleDeckResult, String> nameColumn = new TableColumn<>("Deck name");
	nameColumn.setPrefWidth(200);
	TableColumn<BattleDeckResult, Double> winRateColumn = new TableColumn<>("Win rate");
	winRateColumn.setPrefWidth(150);

	nameColumn.setCellValueFactory(new PropertyValueFactory<BattleDeckResult, String>("deckName"));
	winRateColumn.setCellValueFactory(new PropertyValueFactory<BattleDeckResult, Double>("winRate"));

	winRateColumn.setCellFactory(new Callback<TableColumn<BattleDeckResult, Double>, TableCell<BattleDeckResult, Double>>() {
		public TableCell<BattleDeckResult, Double> call(TableColumn<BattleDeckResult, Double> p) {
			TableCell<BattleDeckResult, Double> cell = new TableCell<BattleDeckResult, Double>() {
				private final Label label = new Label();
				private final ProgressBar progressBar = new ProgressBar();
				private final StackPane stackPane = new StackPane();

				{
					label.getStyleClass().setAll("progress-text");
					stackPane.setAlignment(Pos.CENTER);
					stackPane.getChildren().setAll(progressBar, label);
					setGraphic(stackPane);
				}

				@Override
				protected void updateItem(Double winrate, boolean empty) {
					super.updateItem(winrate, empty);
					if (winrate == null || empty) {
						setGraphic(null);
						return;
					}
					progressBar.setProgress(winrate);
					label.setText(String.format("%.2f", winrate * 100) + "%");
					setGraphic(stackPane);
				}

			};
			return cell;
		}
	});

	rankingTable.getColumns().setAll(nameColumn, winRateColumn);
	rankingTable.getColumns().get(1).setSortType(SortType.DESCENDING);

	backButton.setOnAction(event -> NotificationProxy.sendNotification(GameNotification.MAIN_MENU));
}