i creating application in java retrieves information mysql database , displays in jtable on screen.
the code using , put information defaultlistmodel<> shown below. defaultlistmodel<> fed jtable displays information onto screen.
swingworker<void, void> worker = new swingworker< void, void>() { @override public void doinbackground() { string sql = "select * addabill"; try { statement stmt = globalvars.conn.createstatement(); resultset rs = stmt.executequery(sql); menuoptions.clear(); while(rs.next()){ menuoptions.addelement(rs.getstring(1) + " - " + rs.getstring(2)); } rs.close(); stmt.close(); } catch (sqlexception e) { system.out.println("an error detected! :/"); } return null; } @override public void done(){ loadinggif.setvisible(false); } }; worker.execute();
the issue having information displayed onto screen , isn't. since there no change in query used assuming mysql connection.
the jtable , menuoptions setup this
menuoptions = new defaultlistmodel<>(); menuoptions.addelement(""); menulist = new jlist<>(menuoptions); menulist.setfont(new font("myriad hebrew", font.plain, 32)); menulist.setbackground(color.decode("#005952")); menulist.setforeground(color.decode("#bec423")); menulist.setselectionbackground(color.decode("#660033")); menulist.setselectionforeground(color.decode("#ffffff"));
so question wondering how can make sure information displayed on screen. picture of when displayed , not displayed shown below.
displayed:
not displayed:
on final note information show have keep on re-running code until shown.
any appreciated.
@trashgod @mkorbel
thanks guys, have solved issue adding information table done() function. code below
swingworker<void, void> worker = new swingworker< void, void>() { string[] billitems = null; @override public void doinbackground() { string sql = "select * addabill"; try { statement stmt = globalvars.conn.createstatement(); resultset rs = stmt.executequery(sql); //set cursor last position rs.last(); int totalrows = rs.getrow(); billitems = new string[totalrows]; //set cursor start rs.beforefirst(); while(rs.next()){ int rownum = rs.getrow() - 1; billitems[rownum] = rs.getstring(1) + " - " + rs.getstring(2); } rs.close(); stmt.close(); } catch (sqlexception e) { system.out.println("an error detected! :/"); } return null; } @override public void done(){ menuoptions.clear(); for(int = 0; < billitems.length; i++){ menuoptions.addelement(billitems[i]); } loadinggif.setvisible(false); } };
thanks,
thomas.
Comments
Post a Comment