如何给table表格中每一行上的第一个表格添加一个复选框,通过选择复选框,将对应table上这一行的所有表格中的数据传递到一个List中,或打印出来
代码如何实现,请指教!!!
十分感谢!!!!!!!!

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【lumingvy】截止到2008-07-21 19:04:27的历史汇总数据(不包括此帖):
    发帖的总数量:35                       发帖的总分数:660                      每贴平均分数:18                       
    回帖的总数量:49                       得分贴总数量:6                        回帖的得分率:12%                      
    结贴的总数量:34                       结贴的总分数:640                      
    无满意结贴数:2                        无满意结贴分:40                       
    未结的帖子数:1                        未结的总分数:20                       
    结贴的百分比:97.14 %               结分的百分比:96.97 %                  
    无满意结贴率:5.88  %               无满意结分率:6.25  %                  
    值得尊敬
      

  2.   


    <%
    List<Object> list = new ArrayList<Object>();
    %>
    <table>
    <%
    for(Iterator<Object> it = list.iterator(); it.hasNext(); ) {
      Object o = it.next();
    %>
    <tr><td><%= o.get()%>td></tr><!--这里写代码拿相关属性就可以。-->
    <%
    }
    %>
    </table>
      

  3.   

    谢谢!!!!!
    呵呵,我说的是SWING,谁来帮我
      

  4.   

    改写renderer,加一个checkBox类型的renderer
      

  5.   

    JTable代码static class BooleanRenderer extends JCheckBox implements TableCellRenderer, UIResource
        {
            private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1); public BooleanRenderer() {
        super();
        setHorizontalAlignment(JLabel.CENTER);
                setBorderPainted(true);
    }        public Component getTableCellRendererComponent(JTable table, Object value,
           boolean isSelected, boolean hasFocus, int row, int column) {
        if (isSelected) {
            setForeground(table.getSelectionForeground());
            super.setBackground(table.getSelectionBackground());
        }
        else {
            setForeground(table.getForeground());
            setBackground(table.getBackground());
        }
                setSelected((value != null && ((Boolean)value).booleanValue()));            if (hasFocus) {
                    setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
                } else {
                    setBorder(noFocusBorder);
                }            return this;
            }
        }
      

  6.   

    class MyTableModel_Mold_BOM extends  DefaultTableModel{

    public MyTableModel_Mold_BOM(Vector data,Vector columns){
    super(data,columns);
    }
    public   boolean   isCellEditable(int   row,int   column){
       
    if (column == 0||column == 15||column == 18||column == 19||
    column == 20||column == 21){
    return false;
    }
    else 
    return true;
    }

    public Class<?> getColumnClass(int columnIndex) {
    if(columnIndex==3 || columnIndex==18){
    return Boolean.class;
    }
    else
    return Object.class;
    }
    public void mysetValueAt(Object aValue, int rowIndex, int columnIndex) {
    ((Vector)data_Mold_BOM.get(rowIndex)).set(columnIndex,aValue);
    } }用這樣的類 定義你的model   就行了   如果哪個需要是復選框  就把它的返回值變成Boolean就行了 傳進jtable數據的時候   這個欄位傳入true 或者false就會自動變成復選框了 ~~  (不用去定義renderer)
      

  7.   

    自定义个tablemodel
    然后重写getColumnClass()方法。复选框的话,返回Boolean.class。
    否则返回String.class。6楼正解~
      

  8.   

    jtable的model属性,表设置里将列类型设为boolean
      

  9.   

    return Boolean.TRUE就行了吧,table会自动识别的