table.select() and focus are not remaining on the same row

Hi,

I am trying to select a row programmatically. I have tried multiple ways to implement the same using the itemClickListener, ValueChangeListener. In all the cases, the focus (the dotted line) does not remain on the row i am setting to select. I have tried both table.select() and table.setValue().

I am posting my test code too. If anyone has any ideas, please post them.

Thanks.

public void init() {
setName(“MatchingTablePanel”);
buildPanel();
}

public void buildPanel() {
	
	this.removeAllComponents();
	
	addComponent(table);
	
	table.setMultiSelect(true);
	table.setImmediate(true);
	table.setSelectable(true);
	table.setPageLength(10);
	table.setNullSelectionAllowed(false);
	
	table.addListener((ItemClickListener) this);
	
	table.addContainerProperty("Checkbox", CheckBox.class, null);
            table.addContainerProperty("String", String.class, null);
    
    for (int i = 0; i < 10; i++) {
        Object id = table.addItem();
        table.getContainerProperty(id, "Checkbox").setValue(new CheckBox());
        table.getContainerProperty(id, "String").setValue("row " + id);
    }
    HashSet set = new HashSet();
    set.add(1);
    table.setValue(set);

// table.addShortcutListener(new ShortcutListener(“Down”, ShortcutAction.KeyCode.ARROW_DOWN, null) {
// public void handleAction(Object sender, Object target) {
// table.setSelectable(true);
// System.out.println("target: " + target);
// System.out.println("table.getValue(): " + table.getValue());
// table.requestRepaint();
// }
// });

    final Label selected = new Label("No selection");
    addComponent(selected);
    
    table.addListener(new Table.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
           System.out.println("in valueChangeEvent " + table.getValue());
            Set<?> value = (Set<?>) event.getProperty().getValue();
            if (null == value || value.size() == 0) {
                selected.setValue("No selection");
            } else {
                selected.setValue("Selected: " + table.getValue());
            }
            
            table.select(3);
            HashSet set = new HashSet();

// set.add(2);
set.add(4);
// table.setValue(set);
}
});
}

public void itemClick(ItemClickEvent event) {
	table.setSelectable(true);
	int itemId = (Integer)event.getItemId();
	
	if(event.isDoubleClick()){
		HashSet set = new HashSet();

// set.add(itemId);
set.add(itemId + 1);
table.setValue(set);
table.requestRepaint();
}
}

I have made the following change…

removed the valueChangeListener and ItemClickListener

and edited the shortcutListener:

  table.addShortcutListener(new ShortcutListener("Down", ShortcutAction.KeyCode.ARROW_DOWN, null) {
        public void handleAction(Object sender, Object target) {
        	int value = (Integer) table.getValue();
        	if(value == 10) value = 0;
        	table.select(value+2);
        	table.setCurrentPageFirstItemIndex(value+2);
        }
    });

Sometimes i have noticed the cursor moves back to the top row of the table during the traversal. Should i find a better solution, i will post it for those who might need it.