开发者

JTable using binding, how to get selected Element?

开发者 https://www.devze.com 2023-02-19 00:49 出处:网络
I\'m using binding machanism to show data from database table in 开发者_高级运维jTable. I\'ve had problem with adding new Element and refreshing jTable, but finally I solved it (observable property in

I'm using binding machanism to show data from database table in 开发者_高级运维jTable. I've had problem with adding new Element and refreshing jTable, but finally I solved it (observable property in List). Now I want to get Element from jTable, change it (setters) and save changes (flush?). How can I achieve it?

Thanks in advance!


OK, solved.

Element elem = (Element) list.get(jTable.convertRowIndexToModel(jTable.getSelectedRow()));

where:
Element - entity class
list - entityManager.createQuery("SELECT e FROM Element e").getResultList();

Make sure list is observable (to see changes in jTable immidiately).

0

精彩评论

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