java - JavaFX: TableView, ObservableList and updating TableColumn -
i have following problem, i'm trying make gui input numbers , show in linechart
, tableview
. numbers on xaxis
, left column weeks , numbers on yaxis
, right column balances. it's supposed update balance if input same week twice. works out fine tableview
. adds doesn't update values.
public class linechartsample extends application { static final borderpane root = new borderpane(); static final hbox tabcha = new hbox(); static final gridpane texlab = new gridpane(); static final label woche = new label("woche: "); static final textfield wochet = new textfield(); static final label kontostand = new label("kontostand: "); static final textfield kontostandt = new textfield(); static final button hinzaend = new button("hinzufügen / Ändern"); static final button loeschen = new button("löschen"); static final label text = new label(); static final tableview<xychart.data<number, number>> table = new tableview<xychart.data<number, number>>(); public void start(stage stage) { numberaxis xaxis = new numberaxis(); xaxis.setlabel("woche"); numberaxis yaxis = new numberaxis(); yaxis.setlabel("kontostand"); linechart<number, number> linechart = new linechart<number, number>(xaxis, yaxis); linechart.settitle("kontostände 2014"); xychart.series<number, number> series1 = new xychart.series<number, number>(); series1.setname("konto 1"); linechart.getdata().add(series1); tablecolumn<xychart.data<number, number>, number> woche = new tablecolumn<xychart.data<number,number>, number>("woche"); tablecolumn<xychart.data<number, number>, number> kontostand = new tablecolumn<xychart.data<number,number>, number>("kontostand"); woche.setcellvaluefactory(new propertyvaluefactory<xychart.data<number, number>, number>("xvalue")); kontostand.setcellvaluefactory(new propertyvaluefactory<xychart.data<number, number>, number>("yvalue")); woche.setsorttype(tablecolumn.sorttype.ascending); table.setitems(series1.getdata()); table.getcolumns().add(woche); table.getcolumns().add(kontostand); table.getsortorder().add(woche); tabcha.getchildren().addall(table, linechart); texlab.add(woche, 0, 0); texlab.add(wochet, 1, 0); texlab.add(kontostand, 2, 0); texlab.add(kontostandt, 3, 0); texlab.add(hinzaend,4,0); texlab.add(loeschen,0,1); texlab.add(text, 0, 2, 4, 1); hinzaend.setonaction(e -> { try { text.settext(""); int index = 0; boolean vorhanden = false; (data<number, number> data: series1.getdata()) { if(data.getxvalue() == (number)integer.parseint(wochet.gettext())) { data.setyvalue(double.parsedouble(kontostandt.gettext())); series1.getdata().get(index).setyvalue(double.parsedouble(kontostandt.gettext()));; vorhanden = true; } index += 1; system.out.println(index); } if (!vorhanden) { series1.getdata().add(new xychart.data<number, number>(integer.parseint(wochet.gettext()), double.parsedouble(kontostandt.gettext()))); } if (root.gettop() != tabcha) { root.settop(tabcha); } table.sort(); system.out.println(series1.getdata()); } catch (numberformatexception ex) { text.settext("falsche eingabe"); } }); loeschen.setonaction(e -> { text.settext(""); try { (data<number, number> data: series1.getdata()) { if(data == table.getselectionmodel().getselecteditem()) { linechart.getdata().get(0).getdata().remove(data); } if(series1.getdata().isempty()) { root.getchildren().remove(tabcha); } } if (table.getselectionmodel().isempty()){ text.settext("keine elemente selektiert"); } if(series1.getdata().isempty()) { text.settext("keine elemente zum löschen vorhanden!"); root.getchildren().remove(tabcha); } }catch (concurrentmodificationexception ex){ } }); root.setbottom(texlab); scene scene = new scene(root, 800, 600); stage.settitle("liniendiagramm"); stage.setscene(scene); stage.show(); } public static void main(string[] args) { launch(args); } }
Comments
Post a Comment