【问题标题】:Dynamic table in lwuitlwuit中的动态表
【发布时间】:2011-02-14 13:34:47
【问题描述】:

如何在 lwiit 中创建动态表

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

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

【问题讨论】:

    标签: java java-me lwuit


    【解决方案1】:

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

        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,现在已经下载使用了......
    • @Suhrob:我已经发布了示例代码。在这里,我使用 bean 类来动态获取表中的值。您必须创建 bean 类,或者您也可以使用其他技术。
    • 你好@bhakki 我正在做一个开发航班信息显示系统的项目,我已经完成了它,接下来我想做的是在手机上显示航班信息。那是我使用套接字发送的 kxml 解析数据,现在我需要动态创建表模型并填充表项。这就是为什么你能帮助我......展示一个如何在表格中动态添加项目的工作示例......提前谢谢你!另外我想@user237383 分享你的工作示例
    • 如何获取这些值?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-27
    • 1970-01-01
    相关资源
    最近更新 更多