Trouble with refreshing and deleting data in JPanels
I'm learning how to use Java Swing and tried my hand at creating a calendar or day planner. Essentialy i have a vector that store Detail objects, each object containing an hour, minute and text field, with the ability to activate it. I have a JPanel that is used to add new objects to the vector, but how do i refresh the JPanel or JFrame to show the new entry (i know the vector will not store the new entry when i close and reopen the app, i already have plans to serialize the vector). The other problem i have is that each entry has a delete button associated to it, but i can't get that to delete the entry, even though i've made the index a global variable. Eventually i will need to be able to do the same with the checkbox, where i can turn it off so the entry is invisible. The code i have is below:
Here are some debugging clues:
Add a println() to show the value of row after you have added it. You'll need that later.
allDetails.add(row);
System.out.println("row=" + row); // show value of row
In the delete button listener add these:
class DelButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Component obj = (Component)e.getSource();
Component parent = obj.getParent();
System.out.println("Deleting " + obj + "\n p=" + parent + "\n gp=" + parent.getParent());
If you delete by index, the indexes of the following rows change by -1. You need to find a reference to the object to be deleted and delete using that. The println()s I've given you should allow you to get the references to the objects to be deleted.
After you remove components from the GUI display, you'll need to call validate() on one of the containers to have the GUI refreshed to show the removal.