I have created a jtable that hosts a cell that is a combobox I can get the combobox to populate the jtable but once I restart the program the cells become completely empty. I need a way to save the changes so that once the program is restarted the changes made will remain.( Noted: I have searched solutions for this but to no advance.)
String path ="C:\\Users\\GrantAJ\\Documents\\Comment Matrix";
File folder = new File(path);'File[] listOfFiles= folder.listFiles();
////// filters file objects in java to populate jcombobox with just the name /////
List<String> fileNames = new ArrayList<String>();
for(File files1: listOfFiles){
if(files1.isFile()){
fileNames.add(files1.getName());
}else if (files1.isDirectory())
{ System.out.print("Directory : );
}
final JComboBox jList1 = new JComboBox(listOfFiles);
jList1.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent ae)
{
JOptionPane.showMessageDialog(null, files1.getName());
}
});
TableColumn col = jTable_Files_Name.getColumnModel().getColumn(4);
col.setCellEditor(new DefaultCellEditor(jList1));
}
Object[] row = new Object[6];
// fill the rows and columns
row[0] = file.getName();
row[1] = file.getAbsolutePath();
row[2]= dt;
row[3]=sb.toString();
row[4]=files1.getName();
row[5]=hostname;
model.addRow(new Object []{row[0],row[1],row[2],row[3],"",row[5]});
}
}catch(Exception e){e.printStackTrace();}
Try to build an "AbstractTableModel". This table model will contains your data and could be saved.
To load your model, call new JTable(your_model).
You can look here for more help : http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#data
Good luck.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.