首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

jtable有关问题,小弟我在jtable显示界面的下面加入“上一条”“下一条”“第一条”“到最后”按钮,当单击这些按钮时,jtable显示到指定行

2012-01-30 
jtable问题,我在jtable显示界面的下面加入“上一条”“下一条”“第一条”“到最后”按钮,当单击这些按钮时,jtable

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就向下了

热点排行