JTable w/ JButton Wierdness...

I am having a problem with the removal of a cell value in a JTable if the value is a JButton. I cannot get this to happen when using a JLabel as the value in a cell. The only component that causes this problem is JButton.

Here's my logic:

1.) Click button to scan a part of the filesystem for XML files.

2.) With the XML files found populate the JTable with the fileName and a button to view the XML in a JEditorPane/JDialog (2 cols).

3.) Select a few of the rows in the JTable.

4.) Click a button to process the XML files selected. (For each row processed a JButton is placed in the last column (column 3), of which has an listener that processes events on itself.)

5.) Click button to scan a part of the filesystem again to refresh the JTable.

Sometimes "SOME" of the buttons that were inserted into column 3 hang around. Sometimes it's one of them, sometimes it's a few of them, sometimes it's all of them! I also have sorting built into this JTable. When I click on a column to sort the data, these buttons that are sticking around do not go with their respective row. If I write a loop to go through the values in the table's cells, the buttons do not exist!

This rarely happens, so there aren't any steps I can take to reproduce it...

I have monkied with the EventQueue for a while now, but I haven't found the solution... I have a sneaky feeling it's thread related...

Any insights would be greatly appreciated!

(BTW, before I put sorting in, the same thing was happening)

[1569 byte] By [Woopera] at [2007-10-3 8:15:50]
# 1

I definitely agree that it sounds event thread related.

> of which has an listener that processes events on itself.

Have you tried doing whatever this does (is this the part that removes the rows?) in an invokeLater? That's just a guess, but an event triggered by a button that removes the button certainly sounds like the kind of thing Swing could be upset about...

kindofbluea at 2007-7-15 3:20:55 > top of Java-index,Desktop,Core GUI APIs...
# 2

> I definitely agree that it sounds event thread

> related.

>

> > of which has an listener that processes events on

> itself.

>

> Have you tried doing whatever this does (is this the

> part that removes the rows?) in an invokeLater?

It's not in an invokeLater(), but that shouldn't matter since it's the only thing in the actionPerformed() method... When clicking on the button that was inserted into the cell, a dialog is displayed showing the results of parsing the XML file.

The rows are removed when you click on a button named "Find XML Files". Once XML files were found from the search, the rows in the table get wiped out. Then the new rows (the files found on the filesystem) are inserted into the table.

This is the ActionListener for the JButton:

public class XmlParseResultButton extends JButton {

// properites and such

public XmlParseResultButton(){

// more code here

// add a listener to show the results

addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

new XmlParseResultsDialog(frame,

XmlParseResultButton.this);

}

});

}

}

> That's just a guess, but an event triggered by a

> button that removes the button certainly sounds like

> the kind of thing Swing could be upset about...

Thanks for taking a stab...

Woopera at 2007-7-15 3:20:55 > top of Java-index,Desktop,Core GUI APIs...