jTalbe和jComboBox的问题 在JTable里的某一列的每一项都隐藏的对应一个jComboBox,怎么弄啊,很麻烦,关键是jTable的数据也是从数据库中查到的,怎么能再加JComboBox呢?不会做,请大家帮帮忙 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 网上例子太多了,不细说,看链接,或自个搜。http://zhidao.baidu.com/question/40840960.html?fr=qrl 不是那么简单啊 首先是从数据库中查询出来,把数据显示在JTable中,然后,在显示的第8列中的字段加上JComboBox,而且还是隐藏的,我现在困难就是在添加JComboBox的item时,怎么动态的加上从数据库查出的信息,让数据库查出来的这条字段显示,而其他的项不显示?麻烦啊 public class TestAll extends JFrame{ String[] select1={"a","b","c"}; String[] select2={"1","2","3"}; String[] select3={"!","@","#"}; String[][] b={{"a","1","!"},{"b","2","@"},{"c","3","#"}}; public TestAll(){ init(); } private void init(){ Object[] column={"协作工艺类型","协作承制单位","负责人"}; String[][] rowData={{"a","b","c"},{"1","2","3"},{"!","@","#"},}; JTable jt=new JTable(b,column); jt.getTableHeader().setReorderingAllowed(false); TableColumnModel tcm=jt.getColumnModel(); for(int i=0;i<jt.getColumnCount();i++){ JComboBox com=new JComboBox(rowData[i]); tcm.getColumn(i).setCellEditor(new DefaultCellEditor(com)); //实现在哪一行加JComboBox } JScrollPane jsp=new JScrollPane(jt); JPanel jp=new JPanel(new BorderLayout()); jp.add(jsp); this.getContentPane().add(BorderLayout.CENTER,jp); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); this.show(); } public static void main(String[] args){ new TestAll(); }} 我的问题不是怎么加JComboBox,我的JTable的第8项是从数据库查出来的list遍历出来的第8项,正好也是你加进去的JComboBox的某一项,怎么在遍历list时和JComboBox结合啊? 你是不是想得到在jtable里面改变后,得到的值?for (int i = 0; i < tm.getRowCount(); i++) { for (int j = 0; j < tm.getColumnCount(); j++) { System.out.println(tm.getValueAt(i, j)); }} 在jcombobox.addActionListener中加中table.updateUI试下看! 基础者学习困惑. 请教下前辈们,关于GUI的问题 谁用过regexp或者oro计算过正则表达式?有个问题着急求教 JDBC 的 URL 问题 [闭月羞花猫]项目中,最简单的build.xml文件的书写方式 高分提问(Tcp的输出流一定要用PrintWrite或PrintStream吗? 如何定义一个数组类呢? dom转化成字符串的问题。 查询数据库,如果没有结果,返回的是什么数据 (紧急) 如何运行打好的JAR包?点击行吗? 一道面试题====== 请教:继承于ApplicationFramed的窗口关闭,程序结束问题?
http://zhidao.baidu.com/question/40840960.html?fr=qrl
String[] select1={"a","b","c"};
String[] select2={"1","2","3"};
String[] select3={"!","@","#"};
String[][] b={{"a","1","!"},{"b","2","@"},{"c","3","#"}};
public TestAll(){
init();
}
private void init(){
Object[] column={"协作工艺类型","协作承制单位","负责人"};
String[][] rowData={{"a","b","c"},{"1","2","3"},{"!","@","#"},};
JTable jt=new JTable(b,column);
jt.getTableHeader().setReorderingAllowed(false);
TableColumnModel tcm=jt.getColumnModel();
for(int i=0;i<jt.getColumnCount();i++){
JComboBox com=new JComboBox(rowData[i]);
tcm.getColumn(i).setCellEditor(new DefaultCellEditor(com)); //实现在哪一行加JComboBox
}
JScrollPane jsp=new JScrollPane(jt);
JPanel jp=new JPanel(new BorderLayout());
jp.add(jsp);
this.getContentPane().add(BorderLayout.CENTER,jp);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
this.show();
}
public static void main(String[] args){
new TestAll();
}
}
for (int i = 0; i < tm.getRowCount(); i++) {
for (int j = 0; j < tm.getColumnCount(); j++) {
System.out.println(tm.getValueAt(i, j));
}
}