I'm trying to make a program where basically the whole table is made up of different buttons, and i need each button to perform different actions. i got the table layout how i want it but i'm not sure on how to turn my sample string inputs in to jbuttons. I know how to do actionlistener so i'm not worried about that right now i just need to know how to put different buttons inside different cells.
Code:
import java.awt.*;
import javax.swing.*;
import java.util.*;
import javax.swing.DefaultCellEditor;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
public class TableExample
{
public TableExample()
{
JFrame frame = new JFrame("JButtonTable Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DefaultTableModel dm = new DefaultTableModel();
dm.setDataVector(new Object[][]{{"Category 1", "Button 1","Button 4"},{"Category 2", "Button 2","Button 5"},{"Category 3", "Button 3","Button 6"}}, new Object[]{"Category", "Item 1", "Item 2"});
JTable table = new JTable(dm);
// table.getColumn("Show 1").setCellRenderer(new ButtonRenderer());
JScrollPane scroll = new JScrollPane(table);
frame.add(scroll);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args)
{
TableExample te = new TableExample();
}
}