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还是之前的样子