0
其實我有一個在JTable
一個Column
有ComboBox
,我想是改變JTable
「在運行時小號ComboBox
的值,在CheckBox
值更改事件,我打電話的功能,爲我帶來了新的價值,但值沒有變化。 util.RefreshReplicatedDataAndHeader(true,objVector,-1,this, jScroll_ProductStone.getName());
是獲取我的函數JTable
數據。它叫AddComboBoxForJTable
。我提供了我用於更改組合值和實際功能的代碼的一部分,它使JTable與更改後的值組合在一起。非常感謝您提供解決方案。JTableCombo價值觀不改變運行時
if (thaiFlag)
{
combo_Id_Name_tbl.add("Setting");// Table Name
combo_Id_Name_tbl.add("SetID"); //Combo Id
combo_Id_Name_tbl.add("SetThaiName");// Combo Val
combo_Id_Name_tbl.add("Setting"); // Identifer Of Table For Two Combo FromSameTable
combo_Id_Name_tbl.add("Please select required Setting For Selected Lot");
combo_Id_Name_tbl.add("SetID");// ColId For Selected Combo
combo_Id_Name_tbl.add("SetName"); // Col Val For Selected Combo
combo_Id_Name_tbl.add("N/A"); // Col Id For Non JTable Selected Cobo
combo_Id_Name_tbl.add("N/A"); // Combo Filter Col Name
combo_Id_Name_tbl.add("N/A"); // Combo Filter Col Value
ColId_Val_Identifier_TableName_ForCombo.add(combo_Id_Name_tbl);
}
else
{
combo_Id_Name_tbl.add("Setting");// Table Name
combo_Id_Name_tbl.add("SetID"); //Combo Id
combo_Id_Name_tbl.add("SetName");// Combo Val
combo_Id_Name_tbl.add("Setting"); // Identifer Of Table For Two Combo From Same Table
combo_Id_Name_tbl.add("Please select required Setting For Selected Lot");
combo_Id_Name_tbl.add("SetID");// ColId For Selected Combo
combo_Id_Name_tbl.add("SetName"); // Col Val For Selected Combo
combo_Id_Name_tbl.add("N/A"); // Col Id For Non JTable Selected Cobo
combo_Id_Name_tbl.add("N/A"); // Combo Filter Col Name
combo_Id_Name_tbl.add("N/A"); // Combo Filter Col Value
ColId_Val_Identifier_TableName_ForCombo.add(combo_Id_Name_tbl);
}
TableColumnModel tcm = jtblSizeInfo.getColumnModel();
objVector=null;
objVector=new Vector<Object>();
objVector.add(data_SizeInfo);
objVector.add(header_SizeInfo);
objVector.add(data_ForSave_SizeInfo);
objVector.add(colHeader_ForSave_SizeInfo);
objVector.add(AddedCols_Name_Pos);
objVector.add(ColId_Val_Identifier_TableName_ForCombo);
objVector.add(tcm);
Vector<Object> objResultVector = util.RefreshReplicatedDataAndHeader(true, objVector,-1, this, jScroll_ProductStone.getName());
data_SizeInfo =(Vector<Vector<String>>)objResultVector.get(0) ;
header_SizeInfo=(Vector<String>)objResultVector.get(1) ;
data_ForSave_SizeInfo =(Vector<Vector<String>>)objResultVector.get(2) ;
colHeader_ForSave_SizeInfo=(Vector<String>)objResultVector.get(3) ;
TableColumnModel tcm1 = (TableColumnModel)objResultVector.get(4);
// Column Model Is used to get the Columns And Action Listnner Added In Utility Form
Vector<TableColumn> vtc = new Vector<TableColumn>();
int colCount_Ref = tcm.getColumnCount();
for (int i=0;i<colCount_Ref;i++)
{
vtc.add(tcm.getColumn(i));
}
for (int i=0;i<vtc.size();i++)
{
tcm.removeColumn(vtc.get(i));
}
for (int i=0;i<tcm1.getColumnCount();i++)
{
tcm.addColumn(tcm1.getColumn(i));
}
jtblSizeInfo.setColumnModel(tcm);
jtblSizeInfo.repaint();
jtblSizeInfo.revalidate();
}
的代碼添加組合框的JTable是直接跟
public void AddComboBoxForJTable(int colIndex,Vector<String>vectTable_JtblColIdVal_ComboIdentify, int selectedRow,Object currentFormObj,String currentJScrollPane)
{
////// JComboBox comboBox=null;
try
{
String tableName =vectTable_JtblColIdVal_ComboIdentify.get(0);
String comboId =vectTable_JtblColIdVal_ComboIdentify.get(1);
String comboValue =vectTable_JtblColIdVal_ComboIdentify.get(2);
String comboIdentifier =vectTable_JtblColIdVal_ComboIdentify.get(3);
String comboFilterColName =vectTable_JtblColIdVal_ComboIdentify.get(8);
String comboFilterColValue =vectTable_JtblColIdVal_ComboIdentify.get(9);
Vector<String> comboFilter =new Vector<String>();
comboFilter.add(comboFilterColName);
comboFilter.add(comboFilterColValue);
Vector<Vector<String>> comboData=new Vector<Vector<String>>();
//JComboBox comboBox;
DBEngine dbe = new DBEngine();
if (comboFilterColName.equals("N/A"))
{
comboData = dbe.getComboData(tableName, comboId, comboValue,comboValue);
}
else
{
comboData = dbe.getComboData(tableName, comboId, comboValue,comboValue,comboFilter);
}
Vector model = new Vector();
for (int i =0;i<comboData.size();i ++)
{
// model.addElement(new CustomizedComboBox(3, "train"));
String id =comboData.get(i).elementAt(0).toString();
String data= comboData.get(i).elementAt(1).toString();
Item_ it= new Item_(id,data);
model.addElement(it);
}
JComboBox comboBox = new JComboBox(model);
MyActionListenerForJtableCombo_Utility actionListener = new MyActionListenerForJtableCombo_Utility(
vectTable_JtblColIdVal_ComboIdentify, selectedRow, currentFormObj, currentJScrollPane);
actionListener.util=this;
actionListener.tableName=tableName;
comboBox.addActionListener(actionListener);
// DefaultTableModel tblModel = (DefaultTableModel)jtblUtilities.getModel();
TableColumn column= jtbl_General.getColumnModel().getColumn(colIndex);
column.setCellEditor(new javax.swing.DefaultCellEditor(comboBox));
}
catch (Exception ex)
{
ex.printStackTrace();
// Logger.getLogger(ComboBoxEditor.class.getName()).log(Level.SEVERE, null, ex);
}
}
請用[SSCCE](http://sscce.org/)編輯你的問題,用'JComboBox在JTable中作爲'Renderer'和'Editor'作爲 – mKorbel 2012-03-24 10:24:10
更改組合框/表格的模型。爲了更快地獲得更好的幫助,請發佈[SSCCE](http://sscce.org/)。 – 2012-03-24 10:28:20
請學習java命名約定並堅持使用它們 – kleopatra 2012-03-24 10:37:23