当前位置: 代码迷 >> J2SE >> JCheckBox数组怎么获得里面被选中的值
  详细解决方案

JCheckBox数组怎么获得里面被选中的值

热度:136   发布时间:2016-04-24 12:40:26.0
JCheckBox数组如何获得里面被选中的值
Object[][] cells = {  
  {Boolean.FALSE, "必选","",""},  
  {Boolean.FALSE, "可选","",""},  
  {Boolean.FALSE, "必选","",""},  
  {Boolean.FALSE, "可选","",""},  
  {Boolean.FALSE, "必选","",""},};  
  String[] columnNames = {"选择","重要级","文件名","说明"};  


  DefaultTableModel model = new DefaultTableModel(cells, columnNames) {  
  public Class getColumnClass(int columnIndex)  
  {  
  return columnIndex == 0 ? Boolean.class : String.class;  
  }  
  };

------解决方案--------------------
JS,如果checkbox同名的话,可以做为数组传递到后端,后端可以用request.getParameterValues("参数名")取得多值String[]数组;
------解决方案--------------------
添加ItemListener,重载itemStateChanged(ItemEvent e) 处理,在这之中将想要返回的值传递给后台处理对象