| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 838 人关注过本帖
标题:帮帮我
只看楼主 加入收藏
riapguh
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-2-19
收藏
 问题点数:0 回复次数:3 
帮帮我
javax.swing.JTable(java.util.Vector, java.util.Vector)
怎么在这样的表格的单元格中加一个JComboBox
搜索更多相关主题的帖子: util Vector java JComboBox JTable 
2005-12-23 17:33
riapguh
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-2-19
收藏
得分:0 
还有Vector中的数据已改变已后,JTable为什么还是原来的样子,怎么不刷新啊?
2005-12-23 21:24
飘飘叶子
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:34
帖 子:597
专家分:10
注 册:2005-8-17
收藏
得分:0 
JTable是swing中最复杂的组件之一……要说清楚你的问题也不是一句话二句话的事,建议你去看一下JTable的教程

向着软件工程师的目标前进!
2005-12-23 22:07
riapguh
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-2-19
收藏
得分:0 

package setimp;

import java.util.Vector;


import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;


import setimp.TableModel;
import filewr.Filewr;


public class Filenr extends JPanel {

/**
*
*/
private static final long serialVersionUID = -7761241669024684664L;
private JScrollPane jScrollPane = null;
private JTable jTable = null;
private TableModel dtm = null;
private int filelinefied=-1;
Filewr getfile=new Filewr();
/**
* This is the default constructor
*/
public Filenr() {
super();
initialize(0);
}
public Filenr(Vector data,Vector columnNames) {

super();

dtm= new TableModel(data,columnNames);

//System.out.println(dtm);
/*getfile.getfilerow(filename,200);
Vector columnNames=new Vector();
columnNames.addElement ("行号");
columnNames.addElement("内容");
Vector sss=new Vector();
sss=getfile.getfiledata();
inittable(sss,columnNames);*/

initialize(0);

}
public void redtm(Vector data,Vector columnNames){
// dtm= new TableModel(data,columnNames);
jTable.removeColumn(jTable.getColumnModel().getColumn(0));
dtm.setDataVector( data,columnNames);
jTable.repaint() ;
//System.out.println("_________");
}
public Filenr(Vector data,Vector columnNames ,int isd) {

super();
dtm= new TableModel(data,columnNames);
initialize(1);


}

/*用文件内容来出始表格。data为表格数据,columnNames表格字段*/
//private void inittable(Vector data,Vector columnNames){
/*Vector columnNames=new Vector();
columnNames.addElement ("name");
columnNames.addElement("age");
Vector row2=new Vector();
row2.addElement("ddd");
row2.addElement("ss");
Vector data=new Vector();
data.addElement(row2);*/
// dtm= new TableModel(data,columnNames);
/*row2.removeAllElements() ;//clear();
row2.addElement("1");
row2.addElement("2");
jTable.removeAll();dm.setRowCount(0);
data.addElement(row2);
dtm.setDataVector(data,columnNames);*/
// }
/**
* This method initializes this
*
* @return void
*/
private void initialize(int kk) {
this.setSize(725,360);
this.setLayout(null);
if(kk==1){
this.add(getJScrollPane(1), null);
}else{
this.add(getJScrollPane(0), null);
}
}

/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane(int kk) {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new java.awt.Rectangle(3,3,723,360));
if(kk==1){
jScrollPane.setViewportView(getJTable(1));
}else{
jScrollPane.setViewportView(getJTable(0));
}
}
return jScrollPane;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable(int kk) {
System.out.println(jTable == null);
if (jTable == null) {
jTable = new JTable( dtm );
jTable.setRowHeight(20);
System.out.println("________________>"+kk);
try{
if(kk!=1){
jTable.getColumnModel().getColumn(0).setPreferredWidth(35);
jTable.getColumnModel().getColumn(1).setPreferredWidth(670);
}else{
jTable.getColumnModel().getColumn(0).setPreferredWidth(130);
jTable.getColumnModel().getColumn(2).setPreferredWidth(40);
jTable.getColumnModel().getColumn(3).setPreferredWidth(40);
jTable.getColumnModel().getColumn(4).setPreferredWidth(40);
jTable.getColumnModel().getColumn(5).setPreferredWidth(42);
jTable.getColumnModel().getColumn(8).setPreferredWidth(203);
}
}catch(ArrayIndexOutOfBoundsException w){System.out.println("sfffffff");}
/*jTable.getColumnModel().getColumn(0).setHeaderValue("行号");
jTable.getColumnModel().getColumn(1).setHeaderValue("内容");*/

jTable.setBounds(new java.awt.Rectangle(3,3,723,360));

jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
jTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
filelinefied=jTable.getSelectedRow();
}
});
}

//jTable.set
jTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS );
return jTable;
}
public int getfilelinefied(){
return filelinefied;
}
public void setfieldlist(){
Filewr getfile=new Filewr();
getfile.getfieldrow(Hasconf.impconf.get("filename").toString(),Integer.parseInt(Hasconf.impconf.get("filefied").toString()));
Vector dd=getfile.getfilefied();
JComboBox combox = new JComboBox();
for(int i=0;i<dd.size() ;i++){
combox.addItem(dd.get(i).toString());
}


jTable.getColumnModel().getColumn(8).setCellEditor(new DefaultCellEditor(combox));


}
}
就是dtm的数据都变了,而jTable还是之前的样子

2005-12-23 22:29
快速回复:帮帮我
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011435 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved