java - Bind HashTable/Map to Jtable -


i have c# background , i'm pretty new java. trying port windows application mac using java.

the issue have how bind hashtable contains class jtable variables in key show in jtable. in c# wpf it's easy, binding gridview.itemsource dictionary.keys. in java seems more complicated. here have far:

map<files, string> files = new hashmap<files,string>();  public class files {        public files(string files, string duration, string status) {}                    }  public void addfiles(string addfile, string addduration, string addstatus, string path){             files.put(new files(                     addfile, addduration, addstatus),                      path);             } 

in c# class little different, can gridview.itemsource = files.keys , voila, shows upp perfectly. how can achieve similar in java?

i know jtable can use multidimensional array load values, right trying load values of hashtable object[][] tabledata , use:

string[] columnnames = {"file","duration", "status"}; final jtable table = new jtable(tabledata, columnnames); 

the problem don't know how access variables inside class "files" inside hashmap "files".

i know there is: .getkey().getclass() still haven't been able load multidimensional array values of class "files" inside hashmap.

create tablemodel extending base class abstracttablemodel. in here you'll have override appropriate methods (your ide point them out), important 1 being getvalueat().

override 1 in fashion similar to:

@override public object getvalueat(int rowindex, int columnindex) {      switch (columnindex) {      case 0:             return data.get(rowindex).getvaluex; // change you'd call single value map      case 1:             return data.get(rowindex).getvaluey;      case 2:             return data.get(rowindex).getvaluez;      default:             throw new indexoutofboundsexception();      } } 

you can call model data parameter. afterwards, use model argument jtable , should fine.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -