Help!. Can't remove items from Properties class
I have a messaging system built in an applet that stores and reads messages from text files. The main form has a List control of messages (file names) and a TextArea (txtContent) that displays the contents of each file after clicking on it from the list. The contents of each message (text file) are stored in a Properties table
The problem I have is when I remove one message from the list, I have to remove its contents from the Properties table, and that doesn't work, causing my list of msgs and their contents to go out of sync.
This is how I add the items:
private java.awt.List lstMessages = new java.awt.List();
private Properties m_MessagesTable = new Properties();
String SomeMsg;
String SomeContent;
SomeMsg = "msg1";
SomeContent = "test1";
int iKey = lstMessages.getItemCount()+1;
lstMessages.add(SomeMsg, iKey);
m_MessagesTable.put(Integer.toString(iKey), SomeContent);
SomeMsg = "msg2";
SomeContent = "test2";
int iKey = lstMessages.getItemCount()+1;
lstMessages.add(SomeMsg, iKey);
m_MessagesTable.put(Integer.toString(iKey), SomeContent);
When I select a msg from the list, this is how I show its contents:
String sKey = Integer.toString(lstMessages.getSelectedIndex()+1);
txtContent.setText(m_MessagesTable.getProperty(sKey));
And this is how I delete the item after having selected it from the list:
m_MessagesTable.remove(Integer.toString(lstMessages.getSelectedIndex()+1));
lstMessages.remove(lstMessages.getSelectedIndex());
But when I select and delete the first message, the m_MessagesTable goes crazy and the second item from the list can't find its contents from the table anymore. I'm thinking that when I remove the item from lstMessages, the list renumbers the remaining items, which is fine, but the table does not, and that creates a problem.
Anyone can tell me what am I doing wrong?, or how this could be done differently?
Any help will be appreciated.
Guillermo

