java - Populating JTable via tree map and SQL -


i populating jtable using tree map , tree map being being populated via sql, problem can in 1 line populate via tree map, possible write code(i.e counter) saying add new line

this line of code:

library.put("01", new item(res.getstring(2),(res.getstring(3), integer.parseint(res.getstring(4)))); 

"is possible write code(i.e counter) saying add new line"

sounds me holding data in 2 separate data structures, 1 in treemap , 1 in underlying tablemodel of jtable. there's no need this. data should held in tablemodel. see more @ creating tablemodel.

the easiest way go adding row dynamically use defaulttablemodel takes care of firexxx methods update table. write own xxxtablemodel using item objects, may not necessary.

for defaulttablemodel can set model 0 rows (and column names) start, if have no initial data.

string[] cols = { "col 1", "col 2", "col 3" }; defaulttablemodel model = new defaulttablemodel(cols, 0); jtable table = new jtable(model); 

if do have initial data, can use constructor

defaulttablemodel(object[][] data, object[] cols) 

then add rows dynamically, use model.addrow(object[]). like

object[] row = { res.getstring(2),                  res.getstring(3),                   integer.parseint(res.getstring(4))                }; model.addrow(row); 

the table automatically updated calling addrow.

the fact you're using treemap maybe says want data sorted. in case may want sorting , filtering tables


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -