Results 1 to 2 of 2
  1. #1
    jumpman8947 is offline Member
    Join Date
    Feb 2013
    Posts
    38
    Rep Power
    0

    Default jtable, jbuttons

    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.

    Java 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();
    	}
    
    }

  2. #2
    maddy14 is offline Member
    Join Date
    May 2013
    Posts
    14
    Rep Power
    0

    Default Re: jtable, jbuttons

    y jtable..You could make an array of JButtons and put inside GirdLayout .
    or make an array of JButtons and try inserting it inside jtable.I havent tried this though.

Similar Threads

  1. jbuttons
    By sarah jain in forum AWT / Swing
    Replies: 3
    Last Post: 03-16-2011, 07:13 AM
  2. Please help!JButtons
    By fourpixel in forum AWT / Swing
    Replies: 6
    Last Post: 09-29-2010, 01:48 PM
  3. Help with JButtons...
    By ashton in forum New To Java
    Replies: 8
    Last Post: 01-26-2009, 09:38 AM
  4. JButtons
    By jadaleus in forum Advanced Java
    Replies: 4
    Last Post: 10-17-2008, 02:49 AM
  5. JButtons
    By fgasimzade in forum SWT / JFace
    Replies: 1
    Last Post: 12-25-2007, 05:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •