2012-07-23 87 views

回答

2

问题的标题不能反映内部

有只选择行的单元格的任何方式的实际问题?

号一个Vaadin表的整点是反映行以表格形式数据的。表设置为可选跟踪选定行的itemIds与表

可能能够由表中使用ColumnGenerator,并添加监听到生成组件模拟选择单元格。然而,移除监听器可能会很棘手。

或者,您可能希望简单地生成GridLayout中的组件并自行跟踪所选单元格。

最终,这里的方法实际上取决于你想要达到的目标。

+0

谢谢你的回答。我搜索ColumnGenerator并编写了代码,但它不起作用。我试图做一个表(7X24),当我点击一个单元格时,该行中的其他单元格将不会被选中。如果你能给我一个简短的例子,我会很高兴。 – Hasan 2012-07-23 13:17:30

+0

@Hasan:你有没有试过让表setSelectable(false)? – 2012-07-23 13:32:57

+0

不,我没有。代码在这里http://www.manashk.com/java/。程序只创建表并不加载内容。 – Hasan 2012-07-23 13:55:31

1

这取决于你想要完成什么。 (您的问题标题和您的问题细节解决了两个不同的问题。)如果您想知道您是否可以定位特定单元格并为其添加点击监听器,那么当然可以:

//initial layout setup 
final VerticalLayout layout = new VerticalLayout(); 
layout.setMargin(true); 
setContent(layout); 

//Create a table and add a style to allow setting the row height in theme. 
final Table table = new Table(); 
table.addStyleName("components-inside"); 

//Define the names and data types of columns. 
//The "default value" parameter is meaningless here. 
table.addContainerProperty("Sum",   Label.class,  null); 
table.addContainerProperty("Is Transferred", CheckBox.class, null); 
table.addContainerProperty("Comments",  TextField.class, null); 
table.addContainerProperty("Details",  Button.class, null); 

//Add a few items in the table. 
for (int i=0; i<100; i++) { 
    // Create the fields for the current table row 
    Label sumField = new Label(String.format(
        "Sum is <b>$%04.2f</b><br/><i>(VAT incl.)</i>", 
        new Object[] {new Double(Math.random()*1000)}), 
           Label.CONTENT_XHTML); 
    CheckBox transferredField = new CheckBox("is transferred"); 

    //Multiline text field. This required modifying the 
    //height of the table row. 
    TextField commentsField = new TextField(); 
    //commentsField.setRows(3); 

    //The Table item identifier for the row. 
    Integer itemId = new Integer(i); 

    //Create a button and handle its click. A Button does not 
    //know the item it is contained in, so we have to store the 
    //item ID as user-defined data. 
    Button detailsField = new Button("show details"); 
    detailsField.setData(itemId); 
    detailsField.addListener(new Button.ClickListener() { 
     public void buttonClick(ClickEvent event) { 
      // Get the item identifier from the user-defined data. 
      Integer iid = (Integer)event.getButton().getData(); 
      Notification.show("Link " + 
           iid.intValue() + " clicked."); 
     } 
    }); 
    detailsField.addStyleName("link"); 

    //Create the table row. 
    table.addItem(new Object[] {sumField, transferredField, 
           commentsField, detailsField}, 
        itemId); 
} 

//Show just three rows because they are so high. 
table.setPageLength(3); 

layout.addComponent(table); 

检查the documentation可能是有益的。

相关问题