Dynamic table in lwuit

こ雲淡風輕ζ 提交于 2019-11-29 14:47:31

See this sample code. I have created dynamic table with LWUIT using this code.

    Form form = new Form();
    form.setLayout(new BorderLayout());
    ValueBeans[] valueBeans = new ValueBeans[size];     
    // Here you can use Bean array value. This array contains collection of bean class. 
    // You can get the values from this beans class. 
    // You need to create dynamically with your own staff

    Object[][] arrObj = new Object[valueBeans.length, 3];

    TableModel model = new DefaultTableModel(new String[]{"Column 1", "Column 2", "Column 3"}, arrObj) {

      public boolean isCellEditable(int row, int col) {
        return false; // return true if editable cell
         }
      };

for (int index = 0; index < rowValues.size(); index++) {                                   
    model.setValueAt(index, 0, valueBeans[index].getValue1()); // row , column , value
    model.setValueAt(index, 1, valueBeans[index].getValue2()); 
    model.setValueAt(index, 2, valueBeans[index].getValue3()); 
}

    Table table = new Table(model) {

    protected Component createCell(Object value, final int row, final int column, boolean editable) {

    final Component c = super.createCell(value, row, column, editable);
    c.setFocusable(false);
    return c;
     }
    };
    table.setScrollable(false);
    form.addComponent(BorderLayout.CENTER, table);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!