高手帮忙:table表格中如何加复选框 如何给table表格中每一行上的第一个表格添加一个复选框,通过选择复选框,将对应table上这一行的所有表格中的数据传递到一个List中,或打印出来代码如何实现,请指教!!!十分感谢!!!!!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 此回复为自动发出,仅用于显示而已,并无任何其他特殊作用楼主【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 % 值得尊敬 <%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> 谢谢!!!!!呵呵,我说的是SWING,谁来帮我 改写renderer,加一个checkBox类型的renderer 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; } } 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) 自定义个tablemodel然后重写getColumnClass()方法。复选框的话,返回Boolean.class。否则返回String.class。6楼正解~ jtable的model属性,表设置里将列类型设为boolean return Boolean.TRUE就行了吧,table会自动识别的 一个很基础的问题.for循环 html向applet传参数 关于JOptionPane的问题 两种布局方式的分别 关于prepareStatement的setString问题!请高手指教 通过映射实现对类的接管问题求助! 一个小问题帮我看看该怎样写!!! JavaMail读取新浪按附件转发过来的信件的附件出了问题 scjp(yy6) 速度速度! web service client接收list结果的问题 关于JTree渲染器的问题
楼主【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 %
值得尊敬
<%
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>
呵呵,我说的是SWING,谁来帮我
{
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;
}
}
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)
然后重写getColumnClass()方法。复选框的话,返回Boolean.class。
否则返回String.class。6楼正解~