public class TablePanel extends JPanel implements ActionListener,Serializable
{
JTable m_table;
JComboBox combo,combo1;
DefaultTableModel model=new DefaultTableModel();
DefaultComboBoxModel model1=new DefaultComboBoxModel();
DefaultComboBoxModel model2=new DefaultComboBoxModel();
List<String> field;
List<String> attrCode;
TablePanel()
{
m_table=new JTable(model);
m_table.setBackground(Color.WHITE);
model.addColumn("col1");
model.addColumn("col2");
model.addColumn("col3");
model.addColumn("col4");
model.addColumn("col5");
model.addColumn("col6");
JScrollPane scrollpane=new JScrollPane(m_table);
scrollpane.setBackground(Color.WHITE);
Dimension d = m_table.getPreferredSize();
scrollpane.setPreferredSize(
new Dimension(d.width,m_table.getRowHeight()*15+1));
add(scrollpane);
}
attrCode = service.getAllAttributes(value);
combo1=new JComboBox(model2);
model1.addElement(attrCode.get(0));
model1.addElement(attrCode.get(1));
model1.addElement(attrCode.get(2));
model1.addElement(attrCode.get(3));
model1.addElement(attrCode.get(4));
model1.addElement(attrCode.get(5));
model1.addElement(attrCode.get(6));
col=m_table.getColumnModel().getColumn(0);
col.setCellEditor((new DefaultCellEditor(combo1)));
combo2=new JComboBox(model3);
model3.addElement(trans.get(0));
model3.addElement(trans.get(1));
model3.addElement(trans.get(2));
model3.addElement(trans.get(3));
model3.addElement(trans.get(4));
col=m_table.getColumnModel().getColumn(2);
col.setCellEditor((new DefaultCellEditor(combo2)));} }
我有一张桌子,桌子上有一些列。两列现在有组合框我想做的是,当用户从 column1 组合框中选择一些值时,根据用户选择的值 column2 组合框应该被填充。例如,如果用户从 column1 组合框中选择 value1,则 column2 组合框将仅显示与 value1 对应的值。