我如何在CODENAME ONE的表的每一行上添加按钮?

问题描述 投票:0回答:1
Form hi = new Form("Table", new BorderLayout());
TableModel model = new DefaultTableModel(new String[] {"Col 1", "Col 2", "Col 3","col4"}, new Object[][] {
{"Row 1", "Row A", "Row X"},
{"Row 2", "Row B can now stretch", null},
{"Row 3", "Row C", "Row Z"},
{"Row 4", "Row D", "Row K"},
}) {
    public boolean isCellEditable(int row, int col) {
        return col != 0;
    }
};

Table table = new Table(model){@Override受保护的TableLayout.Constraint createCellConstraint(Object value,int row,int column){TableLayout.Constraint con = super.createCellConstraint(value,row,column);if(column == 3){//如何在每行上添加一个按钮?}con.setWidthPercentage(33);返回骗局}};hi.add(BorderLayout.CENTER,table);

java codenameone
1个回答
0
投票
Form hi = new Form("Table", new BorderLayout());
TableModel model = new DefaultTableModel(new String[] {"Col 1", "Col 2", "Col 3","col4"}, 
new Object[][] {
{"Row 1", "Row A", "Row X"},
{"Row 2", "Row B can now stretch", null},
{"Row 3", "Row C", "Row Z"},
{"Row 4", "Row D", "Row K"},
}) {
    public boolean isCellEditable(int row, int col) {
        return col != 0;
    }
};
Table table = new Table(model) {
@Override
protected TableLayout.Constraint createCellConstraint(Object value, int row, int 
column) {
    TableLayout.Constraint con =  super.createCellConstraint(value, row, column);
    if(column == 3) {
        //how can i add a button here on each row ?
    }
        con.setWidthPercentage(33);
        return con;
    }
};
hi.add(BorderLayout.CENTER, table);
© www.soinside.com 2019 - 2024. All rights reserved.