【发布时间】:2014-08-29 22:36:36
【问题描述】:
我有一个问题,直到我发现但没有按预期工作......
下面是我有一个包含以下列的表格视图 AV1 | AV2 | AV3 | AV4 |和 我希望在任何单元格中输入新值后,SUM 列会自动更新为列总和 AV1: AV4 示例:
更改列 AV1: AV4 中的任何值后,列总和自动更新其值
| AV1 | AV2 | AV3 | AV4 | SUM |
|----- |----- |----- |----- |----- |
| 5 | 5 | 5 | 5 | 20 |
| 1 | 2 | 3 | 4 | 10 |
| 3 | 7 | 10 | 5 | 25 |
我的代码:
col_av4.setCellFactory((TableColumn<Notas, BigDecimal> param) -> new EditingCellNotas());
col_av4.setOnEditCommit((CellEditEvent<Notas, BigDecimal> t) -> {
t.getRowValue().setMediaFinal(t.getNewValue());
t.getRowValue().setMediaGeral(media());
});
private BigDecimal media() {
BigDecimal media = new BigDecimal(0);
BigDecimal av1, av2, av3, av4;
av1 = tbl_notas.selectionModelProperty().getValue().getSelectedItem().getAv1();
System.out.println("AV1" + av1);
av2 = tbl_notas.selectionModelProperty().getValue().getSelectedItem().getAv2();
System.out.println("AV2" + av2);
av3 = tbl_notas.selectionModelProperty().getValue().getSelectedItem().getAv3();
System.out.println("AV3" + av3);
av4 = tbl_notas.selectionModelProperty().getValue().getSelectedItem().getAv4();
System.out.println("AV4" + av4);
try {
media = (av1.add(av2).add(av3).add(av4)).divide(BigDecimal.valueOf(4));
} catch (Exception e) {
}
return media;
}
此代码有效,但我需要双击列单元格总和 更新新值
更新类
我按照这个例子https://gist.github.com/james-d/e485ac525c71e20bb453 现在如何按照响应中给出的示例绑定值?
这是我的课堂笔记,我把属性改成了double。
package com.group.sisgefx.model;
// Generated 09/07/2014 20:05:25 by Hibernate Tools 3.6.0
import java.math.MathContext;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
/**
* Notas generated by hbm2java
*/
@Entity
@Access(AccessType.PROPERTY)
@Table(name = "notas", catalog = "sisge")
public class Notas implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private static final MathContext mc = new MathContext(4);
private IntegerProperty _codNota;
private DoubleProperty _av1;
private IntegerProperty _faltas1;
private DoubleProperty _av2;
private IntegerProperty _faltas2;
private DoubleProperty _av3;
private IntegerProperty _faltas3;
private DoubleProperty _av4;
private IntegerProperty _faltas4;
private DoubleProperty _exame;
private DoubleProperty _mediaGeral;
private DoubleProperty _mediaFinal;
private StringProperty _resultado;
private IntegerProperty _totalFaltas;
private Integer codNota;
private Disciplinas disciplinas;
private Aluno aluno;
private Turma turma;
private Double av1;
private Integer faltas1;
private Double av2;
private Integer faltas2;
private Double av3;
private Integer faltas3;
private Double av4;
private Integer faltas4;
private Double exame;
private Double mediaGeral;
private Double mediaFinal;
private String resultado;
private Integer totalFaltas;
public Notas() {
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "cod_nota", unique = true, nullable = false)
public Integer getCodNota() {
if (_codNota == null) {
return this.codNota;
} else {
return _codNota.get();
}
}
public void setCodNota(Integer codNota) {
if (_codNota == null) {
this.codNota = codNota;
} else {
this._codNota.set(codNota);
}
}
//get Property
public IntegerProperty _codNotaProperty() {
if (_codNota == null) {
_codNota = new SimpleIntegerProperty(this, "codNota", codNota);
}
return _codNota;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idDisciplina", nullable = false)
public Disciplinas getDisciplinas() {
return this.disciplinas;
}
public void setDisciplinas(Disciplinas disciplinas) {
this.disciplinas = disciplinas;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "matricula", nullable = false)
public Aluno getAluno() {
return this.aluno;
}
public void setAluno(Aluno aluno) {
this.aluno = aluno;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idTurma", nullable = false)
public Turma getTurma() {
return this.turma;
}
public void setTurma(Turma turma) {
this.turma = turma;
}
@Column(name = "av1", precision = 4)
public Double getAv1() {
if (_av1 == null) {
return this.av1;
} else {
return _av1.get();
}
}
public void setAv1(Double av1) {
if (this._av1 == null) {
this.av1 = av1;
} else {
this._av1.set(av1);
}
}
//get Property
public DoubleProperty _av1Property() {
if (_av1 == null) {
_av1 = new SimpleDoubleProperty(this, "av1", av1);
}
return _av1;
}
@Column(name = "faltas_1")
public Integer getFaltas1() {
if (_faltas1 == null) {
return this.faltas1;
} else {
return _faltas1.get();
}
}
public void setFaltas1(Integer faltas1) {
if (this._faltas1 == null) {
this.faltas1 = faltas1;
} else {
this._faltas1.set(faltas1);
}
}
//get Property
public IntegerProperty _faltas1Property() {
if (_faltas1 == null) {
_faltas1 = new SimpleIntegerProperty(this, "faltas1", faltas1);
}
return _faltas1;
}
@Column(name = "av2", precision = 4)
public Double getAv2() {
if (_av2 == null) {
return this.av2;
} else {
return _av2.get();
}
}
public void setAv2(Double av2) {
if (this._av2 == null) {
this.av2 = av2;
} else {
this._av2.set(av2);
}
}
//get Property
public DoubleProperty _av2Property() {
if (_av2 == null) {
_av2 = new SimpleDoubleProperty(this, "av2", av2);
}
return _av2;
}
@Column(name = "faltas_2")
public Integer getFaltas2() {
if (_faltas2 == null) {
return this.faltas2;
} else {
return _faltas2.get();
}
}
public void setFaltas2(Integer faltas2) {
if (this._faltas2 == null) {
this.faltas2 = faltas2;
} else {
this._faltas2.set(faltas2);
}
}
//get Property
public IntegerProperty _faltas2Property() {
if (_faltas2 == null) {
_faltas2 = new SimpleIntegerProperty(this, "faltas2", faltas2);
}
return _faltas2;
}
@Column(name = "av3", precision = 4)
public Double getAv3() {
if (_av3 == null) {
return this.av3;
} else {
return _av3.get();
}
}
public void setAv3(Double av3) {
if (this._av3 == null) {
this.av3 = av3;
} else {
this._av3.set(av3);
}
}
//get Property
public DoubleProperty _av3Property() {
if (_av3 == null) {
_av3 = new SimpleDoubleProperty(this, "av3", av3);
}
return _av3;
}
@Column(name = "faltas3")
public Integer getFaltas3() {
if (_faltas3 == null) {
return this.faltas3;
} else {
return _faltas3.get();
}
}
public void setFaltas3(Integer faltas3) {
if (this._faltas3 == null) {
this.faltas3 = faltas3;
} else {
this._faltas3.set(faltas3);
}
}
//get Property
public IntegerProperty _faltas3Property() {
if (_faltas3 == null) {
_faltas3 = new SimpleIntegerProperty(this, "faltas3", faltas3);
}
return _faltas3;
}
@Column(name = "av4", precision = 4)
public Double getAv4() {
if (_av4 == null) {
return this.av4;
} else {
return _av4.get();
}
}
public void setAv4(Double av4) {
if (this._av4 == null) {
this.av4 = av4;
} else {
this._av4.set(av4);
}
}
//get Property
public DoubleProperty _av4Property() {
if (_av4 == null) {
_av4 = new SimpleDoubleProperty(this, "av4", av4);
}
return _av4;
}
@Column(name = "faltas_4")
public Integer getFaltas4() {
if (_faltas4 == null) {
return this.faltas3;
} else {
return _faltas4.get();
}
}
public void setFaltas4(Integer faltas4) {
if (this._faltas4 == null) {
this.faltas4 = faltas4;
} else {
this._faltas4.set(faltas4);
}
}
//get Property
public IntegerProperty _faltas4Property() {
if (_faltas4 == null) {
_faltas4 = new SimpleIntegerProperty(this, "faltas4", faltas4);
}
return _faltas4;
}
@Column(name = "exame", precision = 4)
public Double getExame() {
if (_exame == null) {
return this.exame;
} else {
return _exame.get();
}
}
public void setExame(Double exame) {
if (this._exame == null) {
this.exame = exame;
} else {
this._av1.set(exame);
}
}
//get Property
public DoubleProperty _exameProperty() {
if (_exame == null) {
_exame = new SimpleDoubleProperty(this, "exame", exame);
}
return _exame;
}
@Column(name = "media_geral", precision = 4)
public Double getMediaGeral() {
if (_mediaGeral == null) {
return this.mediaGeral;
} else {
return _mediaGeral.get();
}
}
public void setMediaGeral(Double mediaGeral) {
if (this._mediaGeral == null) {
this.mediaGeral = mediaGeral;
} else {
this._mediaGeral.set(mediaGeral);
}
}
//get Property
public DoubleProperty _mediaGeralProperty() {
if (_mediaGeral == null) {
_mediaGeral = new SimpleDoubleProperty(this, "mediaGeral", mediaGeral);
}
return _mediaGeral;
}
@Column(name = "mediaFinal", precision = 4)
public Double getMediaFinal() {
if (_mediaFinal == null) {
return this.mediaFinal;
} else {
return _mediaFinal.get();
}
}
public void setMediaFinal(Double mediaFinal) {
if (this._mediaFinal == null) {
this.mediaFinal = mediaFinal;
} else {
this._mediaFinal.set(mediaFinal);
}
}
//get Property
public DoubleProperty _mediaFinalProperty() {
if (_mediaFinal == null) {
_mediaFinal = new SimpleDoubleProperty(this, "mediaFinal", mediaFinal);
}
return _mediaFinal;
}
@Column(name = "resultado", length = 11)
public String getResultado() {
if (_resultado == null) {
return this.resultado;
} else {
return _resultado.get();
}
}
public void setResultado(String resultado) {
if (this._resultado == null) {
this.resultado = resultado;
} else {
this._resultado.set(resultado);
}
}
//get Property
public StringProperty _resultadoProperty() {
if (_resultado == null) {
_resultado = new SimpleStringProperty(this, "resultado", resultado);
}
return _resultado;
}
@Column(name = "total_faltas")
public Integer getTotalFaltas() {
if (_totalFaltas == null) {
return this.totalFaltas;
} else {
return _totalFaltas.get();
}
}
public void setTotalFaltas(Integer totalFaltas) {
if (this._totalFaltas == null) {
this.totalFaltas = totalFaltas;
} else {
this._totalFaltas.set(totalFaltas);
}
}
//get Property
public IntegerProperty _totalFaltasProperty() {
if (_totalFaltas == null) {
_totalFaltas = new SimpleIntegerProperty(this, "resultado", totalFaltas);
}
return _totalFaltas;
}
}
【问题讨论】:
-
你的
Notas类中有mediaGeralProperty()访问器吗? -
我不能举个例子
标签: java javafx tableview calculator