2011-09-26 7 views
2

관측 ::스크롤 창을 정적으로 만드는 방법은 무엇입니까?

사용자가 테이블의 마지막 셀에 도달하여 Tab 키를 누를 때마다 포커스가 첫 번째 셀, 즉 테이블 상단으로 이동합니다.

table.scrollRectToVisible (rect) 함수를 사용하여 테이블 뷰를 마지막 셀로 다시 가져 왔지만 이로 인해 테이블 ​​값에 잘못된 변경이있는 것처럼 보입니다.

시나리오 :: 만들기 스크롤 창을 특정 위치에 고정시켜 이동을 제어 할 수 있도록합니다. 이 가능하게 어떻게 ..

답변

4

기본적인 접근 방식은 현재 셀에 대해 확인하는 사용자 지정 작업에 테이블의 기본 탐색 작업을 래핑하는 것입니다 ... 미리 감사합니다 : 그것은 마지막 있다면, 할 기본 동작을 재사용하기위한

Object key = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) 
     .get(KeyStroke.getKeyStroke("ENTER")); 
    final Action action = table.getActionMap().get(key); 
    Action custom = new AbstractAction("wrap") { 

     @Override 
     public void actionPerformed(ActionEvent e) { 
      // implement your prevention logic 
      // here: don't perform if the current cell focus is the very cell of the table 
      int row = table.getSelectionModel().getLeadSelectionIndex(); 
      if (row == table.getRowCount() - 1) { 
       int column = table.getColumnModel().getSelectionModel().getLeadSelectionIndex(); 
       if (column == table.getColumnCount() -1) { 
        // if so, do nothing and return 
        return; 
       } 
      } 
      // if not, call the original action 
      action.actionPerformed(e); 
     } 

    }; 
    table.getActionMap().put(key, custom); 
+1

+1 : 아무것도 그렇지 않으면 포장 작업을

코드 예제를 실행하지 않습니다. – camickr

관련 문제