开发者

Java Swing Generate JTable from POJO at runtime

I'm looking for a library able to build at runtime, using some configuration (xml, annotations, ...) and reflection, a complete JTable (model + searchable and sortable jtable) from a collection of POJOS.

I 开发者_如何转开发did not found anything like that on the web and I'm wondering if something already exist before I start to coding this.


The project that sounds the most similar to your requirements is GlazedLists. It provides filtering instead of searching - and there's not really any configuration - it's just an API that provides TableModel/ListModel implementations that wrap your POJO collections.


You can use the simple but useful BeanPropertyTableModel class from swingtools project that uses reflection in order to generate a JTable Model. There are some configuration methods for setting field orders, localizing field names, etc. See this blog post.

List<Account> accounts = ...
BeanPropertyTableModel<Account> model = new BeanPropertyTableModel<Account>(Account.class);
model.setOrderedProperties(Arrays.asList("name", "host", "user", "password"));
model.setData(accounts);
JTable table = new JTable(model);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜