java jtable 表格,Java Jtable电子表格格式

I have problems regarding implementing JTable, specifically the AbstractTableModel. I can create and show data from JTable but my current scenario is different from my usually scenario.

What I want to do is to make my JTable accept an input from user and I want to put other components inside the JTable

Lets say for every row there is a JComboBox, JTextField and a JCheckBox, however when I start to implement the JTable model (AbstractTableModel) I don't know how can I put those components to my JTable?

Since the method getValue from AbstractTableModel return type is of object data types. Do you have any workaround for this kind of problems and by the ways I hate using DefaultTableModel since it lacks flexibility as much as possible I want an AbstractTableModel :) help is really appreciated.

解决方案

You should definitely start with How to Use Tables and study the examples there. While a JTable ins't a spreadsheet, you can calculate derived values in your table's model. This example shows how to use a JComboBox to update other cells in the same row, and these examples similarly contrast the two TableModel implementations you mention. Finally, you can use an available ScriptEngine to evaluate simple arithmetic expressions. For example, the example below prints 42.0.

ScriptEngine engine = mgr.getEngineByExtension("js");

try {

System.out.println(engine.eval("5 * 8 + 2"));

} catch (ScriptException ex) {

ex.printStackTrace(System.err);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值