Ok, I have two columns of my JTable rendered to hold JButtons. When those JButtons are pressed, it will fire a method that opens the appropriate JFrame. My problem is that I can't get the ActionListener for each JButton to respond. Here is the snippets of code that are relevant for the issue at hand.
public class UserControl extends JFrame { ... Object[][] data; String[] columnNames; JTable table; DefaultTableModel model; ... public UserControl(boolean isSOC) { ... table.getColumnModel().getColumn(4).setCellRenderer(new TableCellRenderer() { public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected,boolean isFocused, int row, int col) { final String val = value+""; JButton rendererComponent = new JButton(val); rendererComponent.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { System.out.println("Action performed"); UserControl.this.openContact(val); } }); return rendererComponent; } }); table.getColumnModel().getColumn(5).setCellRenderer(new TableCellRenderer() { public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected,boolean isFocused, int row, int col) { final String val = value+""; JButton rendererComponent = new JButton(val); rendererComponent.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { System.out.println("Action performed"); UserControl.this.openContact(val); } }); return rendererComponent; } }); ... } public void openContact(String s) { for(int i=0;i<contacts.size();i++) { if(contacts.get(i).name.equalsIgnoreCase(s)) { new ContactInfo(s, contacts.get(i).toString()); } } } ... }
Any thoughts?