java - no error then why ObservableList is not working in this project? -
i saw project in previous answer , tried run didn't how pass data parsed text file , insert values observablelist in javafx?
data inputted text file table view , piechart javafx, work except pie chart trying data table view pie chart, have done after few edits can't run anymore
the problem in observablelist piechartdata = fxcollections .observablearraylist()
this code
package show; import java.io.bufferedreader; import java.io.ioexception; import java.nio.charset.standardcharsets; import java.nio.file.files; import java.nio.file.path; import java.nio.file.paths; import java.util.arraylist; import java.util.list; import javafx.application.application; import javafx.beans.property.simpledoubleproperty; import javafx.beans.property.simpleintegerproperty; import javafx.beans.property.simplestringproperty; import javafx.collections.fxcollections; import javafx.collections.observablelist; import javafx.event.event; import javafx.event.eventhandler; import javafx.scene.group; import javafx.scene.scene; import javafx.scene.chart.piechart; import javafx.scene.control.tablecolumn; import javafx.scene.control.tableview; import javafx.scene.control.tableview.tableviewselectionmodel; import javafx.scene.control.cell.propertyvaluefactory; import javafx.scene.layout.vbox; import javafx.stage.stage; public class show_tableview extends application { public tableview < metrics > tableview = new tableview<metrics>(); private observablelist< metrics > datalist = fxcollections.observablearraylist( // /do new metrics(name,wmc,dit,noc ,cbo,rfc,lcom , ce, npm), // want add metrics added dynamically after file parsed ); observablelist<piechart.data> piechartdata = fxcollections .observablearraylist( new piechart.data("cbo", m.getcbo()), new piechart.data("ce", m.getce()), new piechart.data("dit", m.getdit()), new piechart.data("lcom", m.getlcom()), new piechart.data("noc", m.getnoc()), new piechart.data("npm", m.getnpm()), new piechart.data("wmc", m.getwmc())); c.setdata(piechartdata); public static void main(string[] args) { launch(args); } @override public void start(stage primarystage) { primarystage.settitle("java-buddy.blogspot.com"); group root = new group(); tablecolumn name = new tablecolumn("name"); name.setcellvaluefactory(new propertyvaluefactory<metrics, string>( "name")); tablecolumn wmccol = new tablecolumn("wmc"); wmccol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "wmc")); tablecolumn ditcol = new tablecolumn("dit"); ditcol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "dit")); tablecolumn noccol = new tablecolumn("noc"); noccol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "noc")); tablecolumn cbocol = new tablecolumn("cbo"); cbocol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "cbo")); tablecolumn rfccol = new tablecolumn("rfc"); rfccol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "rfc")); tablecolumn lcomcol = new tablecolumn("lcom"); lcomcol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "lcom")); tablecolumn cecol = new tablecolumn("ca"); cecol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "ce")); tablecolumn npmcol = new tablecolumn("npm"); npmcol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "npm")); primarystage.setscene(new scene(root, 200, 200)); primarystage.show(); list<metrics> metric = readmetricfromcsv("c:\\users\\pavi\\desktop\\11.txt"); // let's print metric read csv file (metrics m : metric) { system.out.println(m); } tableview.setitems(fxcollections.observablearraylist(metric)); tableview.getcolumns().addall(name, wmccol, ditcol, noccol, cbocol, rfccol, lcomcol, cecol, npmcol); vbox vbox = new vbox(); vbox.setmaxsize(600, 600); vbox.setspacing(10); piechart c = new piechart(); tableview.setonmouseclicked(new eventhandler<event>() { @override public void handle(event event) { c.setdata(fxcollections.emptyobservablelist()); tableviewselectionmodel<metrics> tableviewselectionmodel = tableview .selectionmodelproperty().get(); metrics m = tableviewselectionmodel.getselecteditem(); if(m==null){ return; } observablelist<piechart.data> piechartdata = fxcollections .observablearraylist( new piechart.data("cbo", m.getcbo()), new piechart.data("ce", m.getce()), new piechart.data("dit", m.getdit()), new piechart.data("lcom", m.getlcom()), new piechart.data("noc", m.getnoc()), new piechart.data("npm", m.getnpm()), new piechart.data("wmc", m.getwmc())); c.setdata(piechartdata); } }); vbox.getchildren().add(tableview); vbox.getchildren().add(c); root.getchildren().add(vbox); } public list<metrics> readmetricfromcsv(string filename) { list<metrics> metricsss = new arraylist<>(); path pathtofile = paths.get(filename); // create instance of bufferedreader // using try resource, java 7 feature close resources try (bufferedreader br = files.newbufferedreader(pathtofile, standardcharsets.us_ascii)) { // read first line text file string line = br.readline(); while (line != null && !line.isempty()) { // loop until lines // read string[] attributes = line.split(" "); // file, using // comma // delimiter metrics valueofmetric = createmetric(attributes); metricsss.add(valueofmetric); // adding metric arraylist // skip empty line // line.isempty() || line.trim().equals("") || // line.trim().equals("\n")) br.readline(); line = br.readline(); } } catch (ioexception ioe) { ioe.printstacktrace(); } return metricsss; } private metrics createmetric(string[] metadata) { string name = metadata[0]; int wmc = integer.parseint(metadata[1]); int dit = integer.parseint(metadata[2]); int noc = integer.parseint(metadata[3]); int cbo = integer.parseint(metadata[4]); int rfc = integer.parseint(metadata[5]); int lcom= integer.parseint(metadata[6]); int ce = integer.parseint(metadata[7]); int npm = integer.parseint(metadata[8]); return new metrics(name,wmc,dit,noc,cbo,rfc,lcom,ce,npm);//,cc } public class metrics { private string name; private int wmc; private int dit; private int noc; private int cbo; private int rfc; private int lcom; private int ce; private int npm; public metrics( string name,int wmc,int dit,int noc,int cbo,int rfc,int lcom, int ce, int npm) { this.name = name; this.wmc = wmc; this.dit = dit; this.noc = noc; this.cbo = cbo; this.rfc = rfc; this.lcom = lcom; this.ce = ce; this.npm = npm; } public string getname() { return name; } public void setname(string name) { this.name = name; } public int getwmc() { return wmc; } public void setwmc(int wmc) { this.wmc = wmc; } public int getdit() { return dit; } public void setdit(int dit) { this.dit = dit; } public int getnoc() { return noc; } public void setnoc(int noc) { this.noc = noc; } public int getcbo() { return cbo; } public void setcbo(int cbo) { this.cbo = cbo; } public int getrfc() { return rfc; } public void setrfc(int rfc) { this.rfc = rfc; } public int getlcom() { return lcom; } public void setlcom(int lcom) { this.lcom = lcom; } public int getce() { return ce; } public void setce(int ce) { ce = ce; } public int getnpm() { return npm; } public void setnpm(int npm) { this.npm = npm; } } }
text file content
gr.spinellis.ckjm.classvisitor 13 2 0 14 74 34 2 9 gr.spinellis.ckjm.classmetricscontainer 3 1 0 3 18 0 2 2 gr.spinellis.ckjm.metricsfilter 7 1 0 6 30 11 2 5 gr.spinellis.ckjm.printplainresults 2 1 0 2 8 0 1 2 gr.spinellis.ckjm.methodvisitor 11 2 0 21 40 0 1 8 gr.spinellis.ckjm.ckjmoutputhandler 1 1 0 1 1 0 3 1
no problem observablelist piechartdata = fxcollections .observablearraylist() empty arrylist.
@override public void start(stage primarystage) { primarystage.settitle("java-buddy.blogspot.com"); vbox root = new vbox(); tablecolumn name = new tablecolumn("name"); name.setcellvaluefactory(new propertyvaluefactory<metrics, string>( "name")); tablecolumn wmccol = new tablecolumn("wmc"); wmccol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "wmc")); tablecolumn ditcol = new tablecolumn("dit"); ditcol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "dit")); tablecolumn noccol = new tablecolumn("noc"); noccol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "noc")); tablecolumn cbocol = new tablecolumn("cbo"); cbocol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "cbo")); tablecolumn rfccol = new tablecolumn("rfc"); rfccol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "rfc")); tablecolumn lcomcol = new tablecolumn("lcom"); lcomcol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "lcom")); tablecolumn cecol = new tablecolumn("ca"); cecol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "ce")); tablecolumn npmcol = new tablecolumn("npm"); npmcol.setcellvaluefactory(new propertyvaluefactory<metrics, double>( "npm")); primarystage.setscene(new scene(root)); primarystage.show(); list<metrics> metric = readmetricfromcsv("c:\\users\\pavi\\desktop\\11.txt"); // let's print metric read csv file (metrics m : metric) { system.out.println(m); } tableview.setitems(fxcollections.observablearraylist(metric)); tableview.getcolumns().addall(name, wmccol, ditcol, noccol, cbocol, rfccol, lcomcol, cecol, npmcol); vbox vbox = new vbox(); vbox.setspacing(10); piechart c = new piechart(); tableview.setonmouseclicked(new eventhandler<event>() { @override public void handle(event event) { c.setdata(fxcollections.emptyobservablelist()); tableviewselectionmodel<metrics> tableviewselectionmodel = tableview .selectionmodelproperty().get(); metrics m = tableviewselectionmodel.getselecteditem(); if (m == null) { return; } observablelist<piechart.data> piechartdata = fxcollections .observablearraylist( new piechart.data("cbo", m.getcbo()), new piechart.data("ce", m.getce()), new piechart.data("dit", m.getdit()), new piechart.data("lcom", m.getlcom()), new piechart.data("noc", m.getnoc()), new piechart.data("npm", m.getnpm()), new piechart.data("wmc", m.getwmc())); c.setdata(piechartdata); } }); hbox boxc = new hbox(); vbox.prefwidthproperty().bind(root.prefwidthproperty()); boxc.setmanaged(true); boxc.getchildren().addall(tableview, c); vbox.getchildren().add(boxc); root.getchildren().add(vbox); }
i hope solve problem
Comments
Post a Comment