(GWT)如何填写表格中选定行的颜色?

(GWT)如何填写表格中选定行的颜色?,gwt,Gwt,我有一个表,用户在其中单击复选框以选择一行 我想让用户在感兴趣的行上计时,并用彩色背景填充该行。在GWT中,我该怎么做 编辑:我想知道如何使用FlexTable实现这一点。非常感谢也许你应该使用手机桌。 以下是一个例子: 在单元格表中,单击单元格时,整行将亮显。您可以根据自己的需要使用css更改突出显示的颜色 请尝试以下代码: public class CellTableExample implements EntryPoint { private static class Cont

我有一个表,用户在其中单击复选框以选择一行

我想让用户在感兴趣的行上计时,并用彩色背景填充该行。在GWT中,我该怎么做


编辑:我想知道如何使用FlexTable实现这一点。非常感谢

也许你应该使用手机桌。 以下是一个例子:

在单元格表中,单击单元格时,整行将亮显。您可以根据自己的需要使用css更改突出显示的颜色

请尝试以下代码:

public class CellTableExample implements EntryPoint {

    private static class Contact {
        private String address; 
        private String name;

        public Contact(String name, String address) {
            super();
            this.address = address; 
            this.name = name; 
        } 
    }

    // The list of data to display.
      private static List<Contact> CONTACTS = Arrays.asList(
        new Contact("John", "123 Fourth Road asdf asdf asdfasdf"),
        new Contact("Mary", "222 Lancer Lane")

      );

    @Override
    public void onModuleLoad() {
        CellTable<Contact> table = new CellTable<Contact>(); 

        //address column
        TextColumn<Contact> addressColumn = new TextColumn<Contact>(){
            @Override
            public String getValue(Contact contact) {
                return contact.address;
            }
        };

        //name column
        TextColumn<Contact> nameColumn = new TextColumn<Contact>(){
            @Override
            public String getValue(Contact contact) {
                return contact.name;
            }
        };

        // Add the columns.
        table.addColumn(nameColumn, "Name");
        table.addColumn(addressColumn, "Address");

        table.setRowCount(CONTACTS.size(), true);
        table.setRowData(0, CONTACTS);

        RootPanel.get().add(table); 
    }

}
公共类CellTableExample实现入口点{
私有静态类联系人{
私有字符串地址;
私有字符串名称;
公共联系人(字符串名称、字符串地址){
超级();
this.address=地址;
this.name=名称;
} 
}
//要显示的数据列表。
专用静态列表联系人=Arrays.asList(
新联系人(“约翰”,“第四大道123号asdf asdf asdf”),
新联系人(“玛丽”,“兰瑟巷222号”)
);
@凌驾
moduleload()上的公共void{
CellTable=新的CellTable();
//地址列
TextColumn addressColumn=新的TextColumn(){
@凌驾
公共字符串getValue(联系人){
返回联系人地址;
}
};
//名称列
TextColumn name column=新建TextColumn(){
@凌驾
公共字符串getValue(联系人){
返回contact.name;
}
};
//添加列。
表.addColumn(名称栏,“名称”);
表.addColumn(addressColumn,“地址”);
table.setRowCount(CONTACTS.size(),true);
表.setRowData(0,联系人);
RootPanel.get().add(表);
}
}

也许你应该使用手机桌。 以下是一个例子:

在单元格表中,单击单元格时,整行将亮显。您可以根据自己的需要使用css更改突出显示的颜色

请尝试以下代码:

public class CellTableExample implements EntryPoint {

    private static class Contact {
        private String address; 
        private String name;

        public Contact(String name, String address) {
            super();
            this.address = address; 
            this.name = name; 
        } 
    }

    // The list of data to display.
      private static List<Contact> CONTACTS = Arrays.asList(
        new Contact("John", "123 Fourth Road asdf asdf asdfasdf"),
        new Contact("Mary", "222 Lancer Lane")

      );

    @Override
    public void onModuleLoad() {
        CellTable<Contact> table = new CellTable<Contact>(); 

        //address column
        TextColumn<Contact> addressColumn = new TextColumn<Contact>(){
            @Override
            public String getValue(Contact contact) {
                return contact.address;
            }
        };

        //name column
        TextColumn<Contact> nameColumn = new TextColumn<Contact>(){
            @Override
            public String getValue(Contact contact) {
                return contact.name;
            }
        };

        // Add the columns.
        table.addColumn(nameColumn, "Name");
        table.addColumn(addressColumn, "Address");

        table.setRowCount(CONTACTS.size(), true);
        table.setRowData(0, CONTACTS);

        RootPanel.get().add(table); 
    }

}
公共类CellTableExample实现入口点{
私有静态类联系人{
私有字符串地址;
私有字符串名称;
公共联系人(字符串名称、字符串地址){
超级();
this.address=地址;
this.name=名称;
} 
}
//要显示的数据列表。
专用静态列表联系人=Arrays.asList(
新联系人(“约翰”,“第四大道123号asdf asdf asdf”),
新联系人(“玛丽”,“兰瑟巷222号”)
);
@凌驾
moduleload()上的公共void{
CellTable=新的CellTable();
//地址列
TextColumn addressColumn=新的TextColumn(){
@凌驾
公共字符串getValue(联系人){
返回联系人地址;
}
};
//名称列
TextColumn name column=新建TextColumn(){
@凌驾
公共字符串getValue(联系人){
返回contact.name;
}
};
//添加列。
表.addColumn(名称栏,“名称”);
表.addColumn(addressColumn,“地址”);
table.setRowCount(CONTACTS.size(),true);
表.setRowData(0,联系人);
RootPanel.get().add(表);
}
}

要操作单击操作上的行样式,请向FlexTable对象添加一个
ClickHandler
。在
onClick(ClickEvent)
中,可以通过FlexTable方法
getCellForEvent(ClickEvent)
单击单元格。返回的单元格包含有关单击的行(和列)号的信息。通过
getRowFormatter().getElement()
可以获取行的元素并向行添加样式名,以添加颜色或直接在代码中设置代码中行的颜色。

要在单击操作中操作行样式,请向FlexTable对象添加
ClickHandler
。在
onClick(ClickEvent)
中,可以通过FlexTable方法
getCellForEvent(ClickEvent)
单击单元格。返回的单元格包含有关单击的行(和列)号的信息。通过
getRowFormatter().getElement()
您可以获取行的元素并向行添加样式名,以添加颜色,或直接在代码中设置代码中行的颜色。

谢谢,这很好。但我想知道如何使用FlexTables来实现这一点?我的代码有点大,所以尝试切换到cell表将是困难和乏味的。谢谢,这很好。但我想知道如何使用FlexTables来实现这一点?我的代码有点大,所以尝试切换到cell表将是困难和乏味的。