java - Using vector with JTable -
java - Using vector<String> with JTable -
i have vector of string type entries formed as:
vector<string> namelst = new vector<string>(); namelst.add("jacob"); namelst.add("stacey");
[...etc]
i not know number of entries - hence vector instead of array. able display names in tale (with possibility of editing). problem is, jtable uses vector implementation uses list (rather table) trying go through entries of namelst , allocate in new vector:
vector<vector<string>> helper = new vector<vector<string>> (string nametmp : namelst){ vector<string> = new vector<string>(); a.add(nametmp); helper.add((vector<string>)a.clone()) }
however table (while formated correct) remains empty. expect info should remain safe , not go out of scope since i'm cloning helper vector. there way vector populate jtable?
edit: illustration - don't have minimum working example, relevant code is:
the display (in gui class):
jpanel nampan; jtable namtab
in constructor:
namepan = new jpanel();
printnames() //method
public void printnames(){ vector<string> label= new vector<string>(); vector<vector<string>> helper = new vector<vector<string>>; for(string nametmp :namelst){ vector<string> = new vector<string>(); a.add(nametmp); helper.add((vector<string>/*just cast*/) a.clone()); } label.add("currently active:"); namtab = new jtable(helper, label); nampan.add(new jscrollpane(namtab)); }
afterwards phone call gui constructor, fill in name list initial names , phone call printnames() method.
i think core problem mismatch of formats - vector looks ['a' 'b' 'c'] wile should column vector: [a] [b] [c]. or in other words seen 2d vector 1 column , multiple rows.
edit2
found - special hovercraft total of eels pushed me create minimal working example. not find critical differences between uploaded , made, when i've made minimum illustration - stripped other gui elements , functionalities saw data! what happened? set dimension restrictions on window size , panel ratios (gridbaglayout) , test strings outside! when entire area available table see text. decided write , fool rather shove under carpet , leave post hanging.
java swing vector jtable
Comments
Post a Comment