2013-09-25 1 views
0

Eclipse.org의 성운 격자를 사용하고 개별 셀에 액세스하려고합니다. grid.select (...)가 수행 할 수있는 개별 GridItem이 아니라 셀입니다. 내가 말했듯이 성운 격자 - 개별 셀 선택 (CellSelectionEnabled)

final Grid grid = new Grid(shell,SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); 
grid.setCellSelectionEnabled(true); 
grid.setHeaderVisible(true); 

GridColumn column = new GridColumn(grid, SWT.None); 
column.setWidth(80); 
GridColumn column2 = new GridColumn(grid, SWT.None); 
column2.setWidth(80); 
for(int i = 0; i<50; i++) 
{ 
    GridItem item = new GridItem(grid, SWT.None); 
    item.setText("Item" + i); 
} 

, grid.select 내가 원하는하지 않은, 전체 행을 선택 : 그래서 나는이 같은 그리드가 있다고 할 수 있습니다. 나는 또한 grid.selectCell (...)을 시도했지만, 어떤 이유로 든 작동하지 않을 것이다. 사용 된 좌표는 정확할 가능성이 높습니다.

Button btn = new Button(shell, SWT.PUSH); 
btn.setText("test"); 
btn.addSelectionListener(new SelectionAdapter(){ 
public void widgetSelected(SelectionEvent e){ 
    Point pt = new Point(400,300); 
    grid.selectCell(pt); 
    } 
}); 

어떤 아이디어입니까?

답변

0

그리드의 경우, 점 좌표는 교차하는 열과 행 항목을 나타냅니다. 즉, x 좌표는 열의 색인을 나타내고, y 좌표는 행 항목 색인입니다.

Button btn = new Button (shell, SWT.PUSH); 
btn.setText ("test"); 
btn.addSelectionListener(new SelectionAdapter() { 
    @Override 
    public void widgetSelected(SelectionEvent e) { 

     // Here the x co-ordinate of the Point represents the column 
     // index and y co-ordinate stands for the row index. 
     // i.e, x = indexOf(focusColumn); and y = indexOf(focusItem); 
     Point focusCell = grid.getFocusCell(); 
     grid.selectCell(focusCell); 

     // eg., selects the intersecting cell of the first column(index = 0) 
     // in the second row item(rowindex = 1). 
     Point pt = new Point(0, 1); 
     grid.selectCell(pt); 
} 
});