title: Multiple object in a single JTable cell
body: <p>Is it possible to have multiple objects inside one <code>JTable</code> cell looking like this where I have two <code>JLabels</code> in each cell on the first row?</p>
  
  <p><img src="https://i.stack.imgur.com/dXA03.png" alt="enter image description here"></p>
  
  <p>The problem I am having in this example is that I can't add any listeners to any <code>JLabels</code>(<code>Icons</code>). My guess is that I need to change something else then the <code>CellRenderer</code>?</p>
  
  <pre><code>public class JTableIcons extends JPanel {
  
      private DefaultTableModel model;
      private JTable table;
  
      public JTableIcons() {
          initModel();
          initTable();
          this.setLayout(new BorderLayout());
          this.add(table, BorderLayout.CENTER);
      }
  
      class MyRenderer implements TableCellRenderer {
  
          @Override
          public Component getTableCellRendererComponent(JTable table, Object value,
                  boolean isSelected, boolean hasFocus, int row, int column) {
  
              JPanel panel = new JPanel();
              if (row == 0) {
                  JLabel lblCol = new JLabel("Column:" + column);
                  Icon icon = UIManager.getIcon("OptionPane.errorIcon");
                  JLabel lblIcon = new JLabel();
                  lblIcon.setIcon(icon);
                  panel.add(lblIcon);
                  panel.add(lblCol);
              } else {
                  JLabel lbl = new JLabel("(" + row + "," + column + ")");
                  panel.add(lbl);
              }
              panel.setOpaque(false);
              return panel;
          }
      }
  
      private void initTable() {
          table = new JTable(model);
          table.setDefaultRenderer(Object.class, new MyRenderer());
          table.setShowGrid(true);
          table.setGridColor(Color.gray);
          table.setRowHeight(80);
      }
  
      private void initModel() {
          String[] cols = { "", "", "" };
          Object[][] rows = { { "", "", "" }, { "", "", "" }, { "", "", "" }, { "", "", "" } };
          model = new DefaultTableModel(rows, cols);
      }
  
      public static void main(String[] args) {
          EventQueue.invokeLater(new Runnable() {
              @Override
              public void run() {
                  JFrame f = new JFrame();
                  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  f.add(new JTableIcons());
                  f.setVisible(true);
                  f.setSize(new Dimension(500, 350));
                  f.setLocationRelativeTo(null);
              }
          });
      }
  }
  </code></pre>