java - Populating TableView in JavaFX From Data in SQLite -


i trying populate tableview data in sqlite database experiencing weird scenario cannot understand causing it.

the tableview populates 2 columns , not populate rest. tablecolumns 'no' , 'date created' not populated when tableview displayed.

this code displays data sqlite database in 'title' , 'description' tableview columns.

please hawk eye me identify going wrong on code. have spent better part of day trying figure out going wrong not seem figure out not doing right. gladly appreciate on this.

here code

  1. main class

blockquote

public class notedb extends application {      @override     public void start(stage stage) throws exception {         parent root = fxmlloader.load(getclass().getresource("listnotesui.fxml"));          scene scene = new scene(root);          stage.setscene(scene);         stage.show();     }       public static void main(string[] args) {         launch(args);     }  } 

blockquote

  1. fxml

blockquote

<?xml version="1.0" encoding="utf-8"?>  <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?>  <splitpane dividerpositions="0.5" maxheight="-infinity" maxwidth="-infinity" minheight="-infinity" minwidth="-infinity" orientation="vertical" prefheight="400.0" prefwidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="notedb.test.listnotesuicontroller">         <items>             <anchorpane minheight="0.0" minwidth="0.0" prefheight="100.0" prefwidth="160.0">                 <children>                     <splitpane dividerpositions="0.5" layoutx="186.0" layouty="-2.0" orientation="vertical" prefheight="196.0" prefwidth="598.0" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0">                         <items>                             <anchorpane minheight="0.0" minwidth="0.0" prefheight="100.0" prefwidth="160.0">                                 <children>                                     <button alignment="top_center" contentdisplay="text_only" layoutx="484.0" layouty="22.0" mnemonicparsing="false" onaction="#newnote" prefheight="54.0" prefwidth="66.0" text="new note" textalignment="center" wraptext="true" />                                 </children>                             </anchorpane>                             <anchorpane minheight="0.0" minwidth="0.0" prefheight="100.0" prefwidth="160.0">                                 <children>                                     <gridpane layoutx="126.0" layouty="2.0" prefheight="94.0" prefwidth="596.0" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0">                                         <columnconstraints>                                             <columnconstraints hgrow="sometimes" maxwidth="441.0" minwidth="10.0" prefwidth="441.0" />                                             <columnconstraints hgrow="sometimes" maxwidth="292.0" minwidth="10.0" prefwidth="155.0" />                                         </columnconstraints>                                         <rowconstraints>                                             <rowconstraints minheight="10.0" prefheight="30.0" vgrow="sometimes" />                                         </rowconstraints>                                         <children>                                             <textfield fx:id="m_search" onaction="#searchnotes" />                                             <label fx:id="labelnos" alignment="center" prefheight="17.0" prefwidth="94.0" text="4 notes" gridpane.columnindex="1" />                                         </children>                                     </gridpane>                                 </children>                             </anchorpane>                         </items>                     </splitpane>                 </children>             </anchorpane>             <anchorpane minheight="0.0" minwidth="0.0" prefheight="100.0" prefwidth="160.0">                 <children>                     <gridpane layoutx="181.0" layouty="98.0" prefheight="196.0" prefwidth="598.0" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0">                         <columnconstraints>                             <columnconstraints hgrow="sometimes" minwidth="10.0" prefwidth="100.0" />                         </columnconstraints>                         <rowconstraints>                             <rowconstraints minheight="10.0" prefheight="30.0" vgrow="sometimes" />                             <rowconstraints minheight="10.0" prefheight="30.0" vgrow="sometimes" />                         </rowconstraints>                         <children>                             <pane prefheight="200.0" prefwidth="200.0" gridpane.rowindex="1">                                 <children>                                     <button layoutx="95.0" layouty="24.0" mnemonicparsing="false" prefheight="54.0" prefwidth="100.0" text="delete" />                                     <button fx:id="btn_medit" layoutx="389.0" layouty="24.0" mnemonicparsing="false" onaction="#editnoterow" prefheight="54.0" prefwidth="94.0" text="edit" />                                 </children>                             </pane>                             <tableview id="tablenotes" fx:id="tablenotes" editable="true" prefheight="200.0" prefwidth="200.0">                                 <columns>                                     <tablecolumn id="nocol" fx:id="nocol" text="no">                                     </tablecolumn>                                     <tablecolumn id="titlecol" fx:id="titlecol" text="title">                                     </tablecolumn>                                     <tablecolumn id="datecreatedcol" fx:id="datecreatedcol" text="date created">                                     </tablecolumn>                                                                         <tablecolumn id="descriptioncol" fx:id="descriptioncol" text="description">                                     </tablecolumn>                                 </columns>                             </tableview>                         </children>                     </gridpane>                 </children>             </anchorpane>         </items>     </splitpane> 

blockquote

  1. controller class

blockquote

public class listnotesuicontroller implements initializable {       @fxml     private label label;      @fxml     private label labelnos;      @fxml     private button newnote;      @fxml     private button btn_medit;          @fxml     private textfield m_search;      @fxml     private tableview tablenotes;      @fxml     private tablecolumn titlecol;      @fxml     private tablecolumn descriptioncol;      @fxml     private tablecolumn datecreatedcol;      @fxml     private tablecolumn nocol;      //start | sqlite     private static connection con;     private static statement stat;     private preparedstatement prep;     //end | sqlite      private observablelist <note> datanotes;       databank dbank = new databank();          @fxml     private void handlebuttonaction(actionevent event) {         system.out.println("you clicked me!");         label.settext("hello world!");     }      @fxml     private void editnoterow(actionevent event) {      }      @fxml     private void newnote(actionevent event) throws ioexception {      }       @fxml     private void searchnotes(actionevent event){      }      @override     public void initialize(url url, resourcebundle rb) {         datanotes = fxcollections.observablearraylist();          nocol.setcellvaluefactory(                 new propertyvaluefactory<note, string>("idno")         );         datecreatedcol.setcellvaluefactory(                 new propertyvaluefactory<note, string>("datecreated")         );         titlecol.setcellvaluefactory(                 new propertyvaluefactory<note, string>("title")         );         descriptioncol.setcellvaluefactory(                 new propertyvaluefactory<note, string>("description")         );           try {                         sqliteconfig config = new sqliteconfig();             con = drivermanager.getconnection("jdbc:sqlite:note.db");             stat = con.createstatement();             stat.executeupdate("create table if not exists notesdb (idno integer primary key autoincrement not null, title varchar(500), description varchar(1000), datecreated datetime default current_timestamp not null);");              resultset rs = con.createstatement().executequery("select idno, title, datecreated, description notesdb");             while (rs.next()) {                 note nt = new note();                 nt.idno.set(rs.getstring("idno"));                 nt.title.set(rs.getstring("title"));                 nt.datecreated.set(rs.getstring("datecreated"));                 nt.description.set(rs.getstring("description"));                 datanotes.add(nt);                             }                         tablenotes.setitems(datanotes);          } catch (sqlexception ex) {             logger.getlogger(listnotesuicontroller.class.getname()).log(level.severe, null, ex);         }      }  } 

blockquote

  1. datamodel class

blockquote

public class note {      public  simplestringproperty title = new simplestringproperty();     public  simplestringproperty description = new simplestringproperty();     public  simplestringproperty datecreated = new simplestringproperty();     public  simplestringproperty idno = new simplestringproperty();      public string gettitle() {         return title.get();     }      public void settitle(string titlestr) {         title.set(titlestr);     }      public string getdescription() {         return description.get();     }      public void setdescription(string descriptionstr) {         description.set(descriptionstr);     }      public string getdatecreated() {         return datecreated.get();     }      public void setdatecreated(string datecreatedstr) {         datecreated.set(datecreatedstr);     }      public string getidno() {         return idno.get();     }      public void setidno(string idnostr) {         idno.set(idnostr);     } } 

blockquote

there mistake regarding property naming. function getdatecreated , idno don't correlate naming convention.

replace

public  simplestringproperty datecreated = new simplestringproperty(); public  simplestringproperty idno = new simplestringproperty(); 

with

public  simplestringproperty datecreated = new simplestringproperty(); public  simplestringproperty idno = new simplestringproperty(); 

and have @ naming conventions properties


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -