日期:2014-05-20  浏览次数:20550 次

jtable问题,我在jtable显示界面的下面加入“上一条”“下一条”“第一条”“到最后”按钮,当单击这些按钮时,jtable显示到指定行。
jtable问题,我在jtable显示界面的下面加入“上一条”“下一条”“第一条”“到最后”按钮,当单击这些按钮时,希望jtable显示到指定行。但是我用什么方法使光标、当前行移到相应的位置。

  int rowCount=0;
  rowCount=super.jtable.getRowCount();
  if (e.getSource()==super.jBgofirst){
  if (super.jtable.getRowCount()<=0) 
  return;
  else 
  { super.jtable.setEditingRow(0);
  super.currentRow.setText("0");
  }
   
  }
  if (e.getSource()==super.jBgolast){
   
  if (super.jtable.getRowCount()<=0) 
  return;
  else 
  { super.jtable.setEditingRow(rowCount - 1);
  super.currentRow.setText(String.valueOf(rowCount - 1));
  }  
  }
  if (e.getSource()==super.jBgoprior){
  int row=0;
  if (rowCount<=0) 
  return ;
  else 
  row=super.jtable.getEditingRow();
  if (row>0)
  { super.jtable.setEditingRow(row - 1);
  super.currentRow.setText(String.valueOf(row - 1));
  }
  }
  if (e.getSource()==super.jBgonext){
  int row=0;
  if (rowCount<=0) 
  return ;
  else 
  row=super.jtable.getEditingRow();
  if (row< rowCount - 1 )
  { super.jtable.setEditingRow(row + 1);
  super.currentRow.setText(String.valueOf(row - 1));
  }
  }


------解决方案--------------------
http://topic.csdn.net/u/20081022/16/86a7cf15-1d53-4675-8af2-51d7572b7730.html
你看看這個 應該能實現你的目的
------解决方案--------------------
点击下一条的事件处理中加入:
Java code

                if (table.getSelectedRow()>=0) {
                    int index = table.getSelectedRow();
                    index++;
                    if (index<table.getRowCount()) {
                        table.getSelectionModel().setSelectionInterval(index, index);
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "select a row please");
                }

------解决方案--------------------
这样就向上了
this.changeSelection(this.getSelectedRow()-1, 0, false, false);
+1就向下了