如何使用 LWUIT - J2ME 在表单元格中添加组合框?

发布于 2024-11-02 08:40:29 字数 885 浏览 8 评论 0原文

我想在表格单元格中添加一个组合框以提供拖放选项 LWUIT。

我已经使用了这个选项..

    private String strCmbBox[] = { "1", "2", "3", "4" };

    ComboBox comboRdoBox = new ComboBox(strCmbBox);
    comboRdoBox.setListCellRenderer(new comboBoxRenderer());

    TableModel model = new DefaultTableModel(new String[] { "Col 1",
            "Col 2", "Col 3" }, new Object[][] {
            {"Row 1",new DefaultTableModel(new String[] { "1" },
            new Object[][] { { comboRdoBox }, { "lbl" } }),
            "Row X" }, { "Row 2", "Row B", "Row Y" },
            { "Row 3", "Row C", "Row Z" }, 
            { "Row 4", "Row D", "Row K" }, });

    Table table = new Table(model);

    table.initComponent();
    f.addComponent(table);

    f.show();

但它返回单元格中所有属性值的地址;而不是显示组合框 在细胞中...

答: com.sun.lwuit.table.DefaultTableModel@f828ed68

任何人都可以帮我解决这个问题......???

I want to add a combo Box in table cell to provide drag n drop option LWUIT.

I have used this option for it ..

    private String strCmbBox[] = { "1", "2", "3", "4" };

    ComboBox comboRdoBox = new ComboBox(strCmbBox);
    comboRdoBox.setListCellRenderer(new comboBoxRenderer());

    TableModel model = new DefaultTableModel(new String[] { "Col 1",
            "Col 2", "Col 3" }, new Object[][] {
            {"Row 1",new DefaultTableModel(new String[] { "1" },
            new Object[][] { { comboRdoBox }, { "lbl" } }),
            "Row X" }, { "Row 2", "Row B", "Row Y" },
            { "Row 3", "Row C", "Row Z" }, 
            { "Row 4", "Row D", "Row K" }, });

    Table table = new Table(model);

    table.initComponent();
    f.addComponent(table);

    f.show();

but it returns as a address n all attributes value in cell ; rather displaying combo Box
in cell...

Ans :
com.sun.lwuit.table.DefaultTableModel@f828ed68

Can any one help me to solve this ... ???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陪你搞怪i 2024-11-09 08:40:29

我明白了..经过一番谷歌搜索后...:D

package examples;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import com.sun.lwuit.ComboBox;
import com.sun.lwuit.Component;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;

import com.sun.lwuit.List;
import com.sun.lwuit.RadioButton;

import com.sun.lwuit.list.ListCellRenderer;
import com.sun.lwuit.table.DefaultTableModel;
import com.sun.lwuit.table.Table;
import com.sun.lwuit.table.TableModel;

class CustomTable extends Table {

    static ComboBox comboRdoBox[];

    public CustomTable(TableModel model) {
        super(model);
        comboRdoBox = new ComboBox[this.getModel().getRowCount()];
    }

    protected Component createCell(Object value, int row, int column,
            boolean editable) {
        System.out.print("row : " + row);
        System.out.println(" column : " + column);

        // if (row == 2) {
        switch (column) {
        case 1:
            if (comboRdoBox[column] == null) {
                comboRdoBox[column] = new ComboBox(DemoTable2.strCmbBox);
                comboRdoBox[column].setListCellRenderer(new rdioBoxRenderer());
            }

            return comboRdoBox[column];
        }

        // }

        return super.createCell(value, row, column, editable);
    }
}

class rdioBoxRenderer extends RadioButton implements ListCellRenderer {

    public rdioBoxRenderer() {
        super("In super");
    }

    public Component getListCellRendererComponent(List arg0, Object value,
            int index, boolean isSelected) {
        // TODO Auto-generated method stub
        setText(" value :" + value + " index: " + (index + 1));
        if (isSelected) {
            setFocus(true);
            setSelected(true);
        } else {
            setFocus(false);
            setSelected(false);
        }
        return this;
    }

    public Component getListFocusComponent(List arg0) {
        setText("");
        setFocus(true);
        setSelected(true);
        return this;
    }

}

public class demoTable extends MIDlet {

    public demoTable() {
        // TODO Auto-generated constructor stub
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        // TODO Auto-generated method stub

    }

    protected void pauseApp() {
        // TODO Auto-generated method stub

    }

    protected void startApp() throws MIDletStateChangeException {
        Display.init(this);
        Form form = new Form("Hello Form");
        // form.setLayout(new BorderLayout());

        TableModel model = new DefaultTableModel(new String[] { "Col 1",
                "Col 2", "Col 3" }, new Object[][] {
                { "Row 1", "Row A", "Row X" }, { "Row 2", "Row B", "Row Y" },
                { "Row 3", "Row C", "Row Z" }, { "Row 4", "Row D", "Row K" }, });

        CustomTable customTable = new CustomTable(model);
        form.addComponent(customTable);
        form.show();

    }
}

I got it .. after some googling ... :D

package examples;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import com.sun.lwuit.ComboBox;
import com.sun.lwuit.Component;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;

import com.sun.lwuit.List;
import com.sun.lwuit.RadioButton;

import com.sun.lwuit.list.ListCellRenderer;
import com.sun.lwuit.table.DefaultTableModel;
import com.sun.lwuit.table.Table;
import com.sun.lwuit.table.TableModel;

class CustomTable extends Table {

    static ComboBox comboRdoBox[];

    public CustomTable(TableModel model) {
        super(model);
        comboRdoBox = new ComboBox[this.getModel().getRowCount()];
    }

    protected Component createCell(Object value, int row, int column,
            boolean editable) {
        System.out.print("row : " + row);
        System.out.println(" column : " + column);

        // if (row == 2) {
        switch (column) {
        case 1:
            if (comboRdoBox[column] == null) {
                comboRdoBox[column] = new ComboBox(DemoTable2.strCmbBox);
                comboRdoBox[column].setListCellRenderer(new rdioBoxRenderer());
            }

            return comboRdoBox[column];
        }

        // }

        return super.createCell(value, row, column, editable);
    }
}

class rdioBoxRenderer extends RadioButton implements ListCellRenderer {

    public rdioBoxRenderer() {
        super("In super");
    }

    public Component getListCellRendererComponent(List arg0, Object value,
            int index, boolean isSelected) {
        // TODO Auto-generated method stub
        setText(" value :" + value + " index: " + (index + 1));
        if (isSelected) {
            setFocus(true);
            setSelected(true);
        } else {
            setFocus(false);
            setSelected(false);
        }
        return this;
    }

    public Component getListFocusComponent(List arg0) {
        setText("");
        setFocus(true);
        setSelected(true);
        return this;
    }

}

public class demoTable extends MIDlet {

    public demoTable() {
        // TODO Auto-generated constructor stub
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        // TODO Auto-generated method stub

    }

    protected void pauseApp() {
        // TODO Auto-generated method stub

    }

    protected void startApp() throws MIDletStateChangeException {
        Display.init(this);
        Form form = new Form("Hello Form");
        // form.setLayout(new BorderLayout());

        TableModel model = new DefaultTableModel(new String[] { "Col 1",
                "Col 2", "Col 3" }, new Object[][] {
                { "Row 1", "Row A", "Row X" }, { "Row 2", "Row B", "Row Y" },
                { "Row 3", "Row C", "Row Z" }, { "Row 4", "Row D", "Row K" }, });

        CustomTable customTable = new CustomTable(model);
        form.addComponent(customTable);
        form.show();

    }
}
怕倦 2024-11-09 08:40:29

回复您给我的旧 的消息问题,像我提供的示例中那样扩展表。

重写 createCell 方法以返回包含它的列的组合框。

In response to your message to my old question, extend Table like in the example I provide.

Override the createCell method to return the combox for the column containing it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文