2012-10-16 2 views
1

그 시점에 한 행만 표시하는 JTable을 만들려고합니다. 다음/이전을 누르면 테이블은 누른 단추에 따라 다음 또는 이전 행을 표시합니다. 다음/Previous가 없으면 JTable은 처음/마지막 요소를 표시합니다. JTable + Next/Previous 버튼에 표시되는 행 제한

코드는 한 번에 하나 개의 행을 표시하기위한

: 다음 - 버튼

tableModel = new DefaultTableModel(data, columnNames); 
    tableModel.setRowCount(0); //If I remove this, the things I add ends up att the 2nd line. 
    tableModel.addTableModelListener(resultTable); 
    resultTable = new JTable(tableModel); 
    scroll = new JScrollPane(resultTable, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 

    final int rows = 1; 
    Dimension d = resultTable.getPreferredSize(); 
    resultTable.setPreferredSize(new Dimension(d.width,resultTable.getRowHeight()*rows)); 

코드 (? 작동하지 않는,에가 이전과 같은 요소를 보여줍니다 무엇을 할) :

  int height = resultTable.getRowHeight()*(rows-1); 
      JScrollBar bar = scroll.getVerticalScrollBar(); 
      bar.setValue(bar.getValue()+height); 

코드 이전 버튼 (작동하지 않음, 위와 동일, 아무 일도 일어나지 않음/변경됨)

  int height = resultTable.getRowHeight()*(rows-1); 
      JScrollBar bar = scroll.getVerticalScrollBar(); 
      bar.setValue(bar.getValue()-height); 

무엇을할까요? 도움을 주시면 감사하겠습니다. 이 문제를 영원히 해결하려고 노력했습니다.

편집 : 여기의 코드에 따라 시도 : JTable row limitation을하지만 난 단지 얻을 행 수를 지정하면 위의 1 행,하지 (10)

+0

정말로 여기 테이블을 원하십니까? – RNJ

+0

테이블이든 상관 없어요. 그냥 쉽게 할 수있는 것처럼 보였습니다. 그것을하는 더 좋은 방법은 무엇입니까? – user1749754

+0

tableModel을 변경 했습니까? 여기서 Jtable은 모델 데이터를 나타냅니다. –

답변