swing - Display tree map in gui java -


firstly new java please can explain things simple possible!

so have treemap, keys dates point strings.

i want display on screen not sure how so.

i did come across jtable. after reasearching confused columns string array (simply titles of 2 columns) whilst data tree map. after looking further online found should create table model after reading through didn't understand needed do. appreciated!

thanks in advance.

the way want display content varies depending on requirement or on how information displayed in user-friendly way.

jtable approach, jtree approach, although, see jtable more standard way it.

i came approach implemented fast trying simplify complex stuff , fulfill understood question:

public class tableexample {  //asuming have treemap static map<date, string> samplemap = new treemap<date, string>();  //initialize sample treemap values (this static block execute first time run app) static {     samplemap.put(createbirthdayfromstring("14/02/1990"), "marcelo's birthday");     samplemap.put(createbirthdayfromstring("29/06/1989"), "oscar's birthday");     samplemap.put(createbirthdayfromstring("21/04/1985"), "carlos' birthday"); }  //this create date object based on given string public static date createbirthdayfromstring(string dateasstring) {     simpledateformat formatter = new simpledateformat("dd/mm/yyyy");     date converteddate = null;     try {         converteddate = formatter.parse(dateasstring);     } catch (parseexception e) {         // print stacktrace , default current date         e.printstacktrace();         converteddate = new date();     }     return converteddate; }  public void init() {     //create jframe display table     jframe mainframe = new jframe();     mainframe.settitle("my table example");     mainframe.setdefaultcloseoperation(jframe.exit_on_close);     mainframe.setsize(520, 520);      //then panel keep our main frame available display other contents     jpanel mypanel = new jpanel();     mypanel.setbounds(mainframe.getbounds());     mypanel.setbackground(color.dark_gray);     mypanel.setvisible(true);      //add panel frame     mainframe.add(mypanel);      //you need specify columns want display in table, case:     string[] columns = new string[] {"birthday", "name"};      //then can create table model 0 rows @ beginning     //the table model define how data in table displayed     //as provide useful methods if want add events or edition capabilities :)     defaulttablemodel defaultmodel = new defaulttablemodel(columns, 0);      //then create table based on model     jtable mytable = new jtable(defaultmodel);      //then fill each table row data of treemap      //we iterate on map obtain records     (map.entry<date, string> entry : samplemap.entryset()) {         defaultmodel.addrow(new object[] {entry.getkey(), entry.getvalue()});     }      //now add table frame     mypanel.add(new jscrollpane(mytable));      //set frame visible     mainframe.setvisible(true); }  /**  * main method execute example  * @param args  */ public static void main(string[] args) {     new tableexample().init(); }    } 

please let me know if helps or have doubt. happy coding! :)


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -