开发者

how I can save 2 value(text & value of that text) to a jtree node

I create a Jtree in java, I would like to add 2 value to each node , I mean is it possible we have 2 value in each node? for example in JCombobox we can assign one value as text and the other value is text value.

combobox item1 =  text1 + value1

combobox item2 =  text2 + value2

combobox item3 =  text3 + value3

So is there any thing like this for Jtree nodes? if not what is your suggestion for store some thing like this?

becaus开发者_运维百科e I want to save this data in database and also retrieve form database, it will help me so much to create my node path.


You can find an example in the Swing Tutorials. There a custom object (of class BookInfo in that case) is attached to each node in the tree. You may do the same with any other object.


In addition to Howard's answer:

Your object can implement a Serializable interface, so you can store it in the database as is. Or, you may store all of object fields in different columns (preferred way). To work with databse, take a look on JDBC and, as an advice for future, at Hibernate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜