本文介绍了lwuit中的动态表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在lwuit中创建动态表

How to create a Dynamic table in lwuit

TableModel model = new DefaultTableModel(
                new String[]{"A", "B", "Call Avg"},
                new Object[][]{
                    {"0", "50", "0.00"},
                    {"0", " " + "2", "0.00"},
                    {"0", "52", "0.00"},}) 
{

            public boolean isCellEditable(int row, int col) {
                return col != 0 ;
            }
        };
        Table table = new Table(model);

这是静态的。我想动态创建行数和列数.Plz帮助

This is for static . I want to create dynamically number of rows and columns .. Plz help

推荐答案

请参阅此示例代码。我使用此代码使用LWUIT创建了动态表。

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);

这篇关于lwuit中的动态表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 03:42