JButton in JTable

Hello all !
I want to create a JTable with Cell (class that I will write which extends JButton) in each cell of the table. Cell should contain a state, say 0,1,2 or 3, which dictates the representation of the cell. A representation of a cell contains a background color and an Icon. In addition, I want that if I press the left button of the mouse, the cell will change his state to 1, then to 2 and back to 1, and the right button of the mouse will change the state to 3, then to 4, and back to 3.
I have tried many ideas based on different examples I found on the Internet, but didn't get what I wanted, and now I'm really confused...
Can anyone help ?
I will be grateful for any help !
Thanks in advance !

First of all thanks for your wish to help !
First of all you have no need to extend JTable. You
just use a DefaultTableModel and add data to the
model.I tried to use DefaultTableModel, but now I don't see the table at all :)
Can you explain why ? The code is following:
public class JCFrame {
     private static void createAndShowGUI() {
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          JCTable table = new JCTable();
          frame.add(table);
          frame.pack();
          frame.setVisible(true);
     public static void main(String[] args) {
          javax.swing.SwingUtilities.invokeLater(
               new Runnable() { public void run() { createAndShowGUI(); } });
public class JCTable extends JTable {
     public JCTable() {
          super(new JCTableModel());               
public class JCCell extends JButton {
     private int state;
     public JCCell(int initialState) {
          state = initialState;
public class JCTableModel extends DefaultTableModel {
     private final int numberOfRows = 2;
     private final int numberOfColumns = 3;
     private Object[][] cellsData = new JCCell[numberOfRows][numberOfColumns];          
     public JCTableModel() {
          for (int i = 0; i < numberOfRows; i++)
               for (int j = 0; j < numberOfColumns; j++)
                    cellsData[i][j] = new JCCell(numberOfRows * i + j);
}In addition, I don't understand why I don't need to extend JTable. If I want to see a table, I should use JTable somewhere, but where ??
If you don't want to see the column headers then you
can use table.setHeader( null );I tried to write this, but the compiler complains that he cannot find symbol method setHeader(...). I neither found this method in Java API. Are you sure about it ?
And one more question:
Should the renderer extend JButton ?
Many thanks !!

Similar Messages

  • Adding JButton into JTable cells

    Hi there!!
    I want to add a JButton into JTable cells.In fact I have got two classes.Class2 has been extended from the AbstractTableModel class and Class1 which is using Class2's model,,,here's the code,,
    Class1
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    public class Class1 extends javax.swing.JFrame {
       //////GUI specifications
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new TestTableButton().setVisible(true);
            Class2 model=new Class2();
            jTable1=new JTable(model);
            jScrollPane1.setViewportView(jTable1);
        // Variables declaration - do not modify                    
        private javax.swing.JScrollPane jScrollPane1;
        // End of variables declaration                  
        private javax.swing.JTable jTable1;
    }Class2
    import javax.swing.table.*;
    public class Class2 extends AbstractTableModel{
        private String[] columnNames = {"A","B","C"};
        private Object[][] data = {
        public int getColumnCount() {
            return columnNames.length;
        public int getRowCount() {
            return data.length;
        public String getColumnName(int col) {
            return columnNames[col];
        public Object getValueAt(int row, int col) {
            return data[row][col];
        public Class getColumnClass(int c) {
            return getValueAt(0, c).getClass();
         * Don't need to implement this method unless your table's
         * editable.
        public boolean isCellEditable(int row, int col) {
            //Note that the data/cell address is constant,
            //no matter where the cell appears onscreen.
                return false;
         * Don't need to implement this method unless your table's
         * data can change.
        public void setValueAt(Object value, int row, int col) {
            data[row][col] = value;
            fireTableCellUpdated(row, col);
    }what modifications shud I be making to the Class2 calss to add buttons to it?
    Can anybody help plz,,,,,??
    Thanks in advance..

    Hi rebol!
    I did search out a lot for this but I found my problem was a bit different,,in fact I want to use another class's model into a class being extended by JFrame,,so was a bit confused,,,hope you can give me some ideas about how to handle that scenario,,I know this topic has been discussed before here many a times and also have visited this link,,
    http://forum.java.sun.com/thread.jspa?threadID=465286&messageID=2147913
    but am not able to map it to my need,,,hope you can help me a bit...
    Thanks .....

  • Multiple JButtons inside JTable cell - Dispatch mouse clicks

    Hi.
    I know this subject has already some discussions on the forum, but I can't seem to find anything that solves my problem.
    In my application, every JTable cell is a JPanel, that using a GridLayout, places vertically several JPanel's witch using an Overlay layout contains a JLabel and a JButton.
    As you can see, its a fairly complex cell...
    Unfortunately, because I use several JButtons in several locations inside a JTable cell, sometimes I can't get the mouse clicks to make through.
    This is my Table custom renderer:
    public class TimeTableRenderer implements TableCellRenderer {
         Border unselectedBorder = null;
         Border selectedBorder = null;
         public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                   boolean hasFocus, int row, int column) {
              if (value instanceof BlocoGrid) {
                   if (isSelected) {
                        if (selectedBorder == null)
                             selectedBorder = BorderFactory.createMatteBorder(2,2,2,2, table.getSelectionBackground());
                        ((BlocoGrid) value).setBorder(selectedBorder);
                   } else {
                        if (unselectedBorder == null)
                             unselectedBorder = BorderFactory.createMatteBorder(2,2,2,2, table.getBackground());
                        ((BlocoGrid) value).setBorder(unselectedBorder);
              return (Component) value;
    }and this is my custom editor (so clicks can get passed on):
    public class TimeTableEditor extends AbstractCellEditor implements TableCellEditor {
         private TimeTableRenderer render = null;
         public TimeTableEditor() {
              render = new TimeTableRenderer();
        public Component getTableCellEditorComponent(JTable table, Object value,
                boolean isSelected, int row, int column) {
             if (value instanceof BlocoGrid) {
                  if (((BlocoGrid) value).barras.size() > 0) {
                       return render.getTableCellRendererComponent(table, value, isSelected, true, row, column);
             return null;
        public Object getCellEditorValue() {
            return null;
    }As you can see, both the renderer and editor return the same component that cames from the JTable model (all table values (components) only get instantiated once, so the same component is passed on to the renderer and editor).
    Is this the most correct way to get clicks to the cell component?
    Please check the screenshot below to see how the JButtons get placed inside the cell:
    http://img141.imageshack.us/my.php?image=calendarxo9.jpg
    If you need more info, please say so.
    Thanks.

    My mistake... It worked fine. The cell span code was malfunctioning. Thanks anyway.

  • JButton in JTable with custom table model

    Hi!
    I want to include a JButton into a field of a JTable. I do not know why Java does not provide a standard renderer for JButton like it does for JCheckBox, JComboBox and JTextField. I found some previous postings on how to implement custom CellRenderer and CellEditor in order to be able to integrate a button into the table. In my case I am also using a custom table model and I was not able to create a clickable button with any of the resources that I have found. The most comprehensive resource that I have found is this one: http://www.java2s.com/Code/Java/Swing-Components/ButtonTableExample.htm.
    It works fine (rendering and clicking) when I start it. However, as soon as I incorporate it into my code, the clicking does not work anymore (but the buttons are displayed). If I then use a DefaultTableModel instead of my custom one, rendering and clicking works again. Does anyone know how to deal with this issue? Or does anyone have a good pointer to a resource for including buttons into tables? Or does anyone have a pointer to a resource that explains how CellRenderer and CellEditor work and which methods have to be overwritten in order to trigger certain actions (like a button click)?
    thanks

    Yes, you were right, the TableModel was causing the trouble, everything else worked fine. Somehow I had this code (probably copy and pasted from a tutorial - damn copy and pasting) in my TableModel:
            public boolean isCellEditable(int row, int col) {
                //Note that the data/cell address is constant,
                //no matter where the cell appears onscreen.
                if (col < 3) {
                    return false;
                } else {
                    return true;
    }A pretty stupid thing when you want to edit the 3rd column...

  • How to get jbuttons under jtable and within menu?

    I've developed a menu and will like to display the results of reading a text file in a jtable with jbuttons underneath on the screen somewhere. Is there a way I can display my jbuttons underneath the jtable?, i.e.
    itemno item desc
    1111 bbb
    2222 ccc
    <button> <button>

    Yes.
    In future Swing related questions should be posted into the camickr forum.

  • Clicking JButton in JTable

    Hello all,
    I have populated a JTable with Buttons and need for them to appear to be clicked (become depressed) when they are clicked.
    Currently, I have found some way to handle click events on them, but the display is not updated to show that they are clicked.
    How can this be done??
    fyi, the click code adds a mouse listener to the table, which determines which cell is clicked based on location and forwards the event to appropriate handler. it goes something like this:
    private void forwardEventToHandlers(MouseEvent e) {
             TableColumnModel columnModel = _table.getColumnModel();
             _column = columnModel.getColumnIndexAtX(e.getX());
             _row    = e.getY() / _table.getRowHeight();
             Object value;
             JButton button = new JButton();
             MouseEvent buttonEvent;
             if(_row >= _table.getRowCount() || _row < 0 ||
                _column >= _table.getColumnCount() || _column < 0)
               return;
             value = _table.getValueAt(_row, _column);
                              // forward an event to handler...
             }

    I have a couple of attempts at this that you may be able to use or at least give you some ideas:
    a) Original attempt
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableButton extends JFrame
        public TableButton()
            String[] columnNames = {"Date", "String", "Integer", "Decimal", "Boolean"};
            Object[][] data =
                {new Date(), "A", new Integer(1), new Double(5.1), new JButton("Delete")},
                {new Date(), "B", new Integer(2), new Double(6.2), new JButton("Delete")},
                {new Date(), "C", new Integer(3), new Double(7.3), new JButton("Delete")},
                {new Date(), "D", new Integer(4), new Double(8.4), new JButton("Delete")}
            DefaultTableModel model = new DefaultTableModel(data, columnNames);
            final JTable table = new JTable( model )
                //  Returning the Class of each column will allow different
                //  renderers to be used based on Class
                public Class getColumnClass(int column)
                    return getValueAt(0, column).getClass();
                //  Don't edit the button column
                public boolean isCellEditable(int row, int column)
                    return column != 4;
            table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
              table.setPreferredScrollableViewportSize(table.getPreferredSize());
            JScrollPane scrollPane = new JScrollPane( table );
            getContentPane().add( scrollPane );
            //  Create button renderer
            TableCellRenderer buttonRenderer = new ButtonRenderer();
            table.setDefaultRenderer(JButton.class, buttonRenderer);
            //  Add table mouse listener
            table.addMouseListener( new ButtonListener(table, 4) );
        public static void main(String[] args)
    //        try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }
    //        catch(Exception e) {}
            TableButton frame = new TableButton();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setLocationRelativeTo( null );
            frame.setVisible(true);
        class ButtonRenderer extends JButton implements TableCellRenderer
            public Component getTableCellRendererComponent(
                JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
                JButton button = (JButton)value;
                if (button == null)
                    setText( "" );
                    getModel().setPressed( false );
                    getModel().setArmed( false );
                else
                    setText( button.getText() );
                    getModel().setPressed( button.getModel().isPressed() );
                    getModel().setArmed( button.getModel().isArmed() );
                return this;
         *  1) Creation of class will determine the column to process mouse events on
         *  a) Mouse pressed will determine the row to process and paint pressed button
         *  b) Mouse clicked will do the actual processing
         *  c) Mouse released will paint the normal button
        class ButtonListener extends MouseAdapter
            private JTable table;
            //  Column from the data model to process mouse events on
            private int column;
            //  The table row when the mouse was pressed
            private int row;
            //  The table column when the mouse was pressed
            private int tableColumn;
            //  Repaint the button on mouse released event
            private boolean paintOnRelease;
            ButtonListener(JTable table, int column)
                this.table = table;
                this.column = column;
             *  Repaint button to show pressed state
            public void mousePressed(MouseEvent e)
                //  Make sure the MouseEvent was on the button column
                if ( !buttonColumn(e) ) return;
                //  Repaint the button for the current row/column
                row = table.rowAtPoint( e.getPoint() );
                tableColumn = table.columnAtPoint( e.getPoint() );
                paintButton( true );
                paintOnRelease = true ;
             *  Do table processing on this event
            public void mouseClicked(MouseEvent e)
                //  Make sure the MouseEvent was on the button column
                if ( !buttonColumn(e) ) return;
                //  Only process a single click
                if (e.getClickCount() > 1) return;
                //  Delete current row from the table
                DefaultTableModel model = (DefaultTableModel)table.getModel();
                model.removeRow( this.row );
                //  Row has been deleted, nothing to repaint
                paintOnRelease = false;
             *  Repaint button to show normal state
            public void mouseReleased(MouseEvent e)
                if (paintOnRelease)
                    paintButton( false );
                paintOnRelease = false;
            private boolean buttonColumn(MouseEvent e)
                //  In case columns have been reordered, we must map the
                //  table column to the data model column
                int tableColumn = table.columnAtPoint( e.getPoint() );
                int modelColumn = table.convertColumnIndexToModel(tableColumn);
                return modelColumn == column;
            private void paintButton(boolean pressed)
                //  Make sure we have a JButton before repainting
                Object o = table.getValueAt(row, tableColumn);
                if (o instanceof JButton)
                    JButton button = (JButton)o;
                    button.getModel().setPressed( pressed );
                    button.getModel().setArmed( pressed );
                    table.setValueAt(button, row, tableColumn);
    }b) Latest attempt:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableButton3 extends JFrame
        public TableButton3()
            String[] columnNames = {"Date", "String", "Integer", "Decimal", ""};
            Object[][] data =
                {new Date(), "A", new Integer(1), new Double(5.1), "Delete0"},
                {new Date(), "B", new Integer(2), new Double(6.2), "Delete1"},
                {new Date(), "C", new Integer(3), new Double(7.3), "Delete2"},
                {new Date(), "D", new Integer(4), new Double(8.4), "Delete3"}
            DefaultTableModel model = new DefaultTableModel(data, columnNames);
            JTable table = new JTable( model )
                //  Returning the Class of each column will allow different
                //  renderers to be used based on Class
                public Class getColumnClass(int column)
                    return getValueAt(0, column).getClass();
            JScrollPane scrollPane = new JScrollPane( table );
            getContentPane().add( scrollPane );
            //  Create button column
            ButtonColumn buttonColumn = new ButtonColumn(table, 4);
        public static void main(String[] args)
            TableButton3 frame = new TableButton3();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setVisible(true);
        class ButtonColumn extends AbstractCellEditor
            implements TableCellRenderer, TableCellEditor, ActionListener
            JTable table;
            JButton renderButton;
            JButton editButton;
            String text;
            public ButtonColumn(JTable table, int column)
                super();
                this.table = table;
                renderButton = new JButton();
                editButton = new JButton();
                editButton.setFocusPainted( false );
                editButton.addActionListener( this );
                TableColumnModel columnModel = table.getColumnModel();
                columnModel.getColumn(column).setCellRenderer( this );
                columnModel.getColumn(column).setCellEditor( this );
            public Component getTableCellRendererComponent(
                JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
                if (hasFocus)
                    renderButton.setForeground(table.getForeground());
                    renderButton.setBackground(UIManager.getColor("Button.background"));
                else if (isSelected)
                    renderButton.setForeground(table.getSelectionForeground());
                     renderButton.setBackground(table.getSelectionBackground());
                else
                    renderButton.setForeground(table.getForeground());
                    renderButton.setBackground(UIManager.getColor("Button.background"));
                renderButton.setText( (value == null) ? "" : value.toString() );
                return renderButton;
            public Component getTableCellEditorComponent(
                JTable table, Object value, boolean isSelected, int row, int column)
                text = (value == null) ? "" : value.toString();
                editButton.setText( text );
                return editButton;
            public Object getCellEditorValue()
                return text;
            public void actionPerformed(ActionEvent e)
                fireEditingStopped();
                System.out.println( e.getActionCommand() + " : " + table.getSelectedRow());
    }

  • JButton in JTable Help

    Hi
    I have successfully added a JButton to a table and am able to click on it and when you do it opens up a new window.
    I have set the cellEditor to my new class which performs the actions of a button. I am wanting the new window which opens up to either be presented in the original frame or update the original frame but I have no idea how to do this.
    Can anyone help me?

    I thought it might be hard to understand
    is a main window with information retrieved from a database. When you click on a button in the JTable it opens up a JDialog which edits information in the database. When you submit the changes it closes the second window down and i am wanting it to refresh the original window with the new information in the database.
    Hope this makes sense

  • JButtons in JTable

    I wish to add JButtons to cells in a JTable using a loop. Using
    table.getColumn("Load to monitor").setCellRenderer(new ButtonRenderer());
    table.getColumn("Load to monitor").setCellEditor(new ButtonEditor(new JCheckBox()));
    adds buttons to all cells in the Load to monitor column. I want to add the buttons one by one in order to use a setName function for each button
    Any help greatly appreciated.

    Don't cross-post. This is a Swing related question and has already been posted in the Swing forum:
    : http://forum.java.sun.com/thread.jspa?threadID=678170

  • Adding JButtons to JTable

    Hello all,
    How can I add JButtons to a JTable?
    I found an article that is supposed to show you how to do just that:
    http://www.devx.com/getHelpOn/10MinuteSolution/20425
    I downloaded the code in the article and it works to an extent - I can see the buttons in the table but the buttons seem as if they are disabled :( Since I used this code in my application, I get the same behavior too.
    Is there a bug in the code? Is there a simpler solution? What am I missing?
    Raj

    Thanks. That makes the button clickable. But now the button changes back to it's old value when you click on another cell. I suppose that's because we have 2 buttons, one for rendering and one for editing. So I added a setValueAt(Object value, int row, int column) to MyModel. This works throws class cast exception.
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    public class ButtonInTable extends JFrame {
        JTable t=new JTable(new MyModel());
        public ButtonInTable() {
            this.getContentPane().add(new JScrollPane(t));
            this.setBounds(50,50,300,200);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            t.setDefaultEditor(Object.class,new ButtonEditor());
            t.setDefaultRenderer(Object.class,new ButtonRenderer());      
        public static void main(String[] args) {
            ButtonInTable buttonInTable1 = new ButtonInTable();
            buttonInTable1.show();
        class ButtonEditor extends JButton implements TableCellEditor {
            Object currentValue;
            Vector listeners=new Vector();
            public ButtonEditor() {
                            this.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                    currentValue=JOptionPane.showInputDialog("Input new value!");
                                    if (currentValue!=null) {
                                        setText(currentValue.toString());
            public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
                currentValue=value;
    //            this.setText(value.toString());
                this.setText( ((JButton)value).getText() );
                return this;
            public Object getCellEditorValue() {
                return currentValue;
            public boolean isCellEditable(EventObject anEvent) {
                return true;
            public boolean shouldSelectCell(EventObject anEvent) {
                return true;
            public boolean stopCellEditing() {
                ChangeEvent ce=new ChangeEvent(this);
                for (int i=0; i<listeners.size(); i++) {
                    ((CellEditorListener)listeners.get(i)).editingStopped(ce);
                return true;
            public void cancelCellEditing() {
                ChangeEvent ce=new ChangeEvent(this);
                for (int i=0; i<listeners.size(); i++) {
                    ((CellEditorListener)listeners.get(i)).editingCanceled(ce);
            public void addCellEditorListener(CellEditorListener l) {
                listeners.add(l);
            public void removeCellEditorListener(CellEditorListener l) {
                listeners.remove(l);
        class ButtonRenderer extends DefaultTableCellRenderer {
            public Component getTableCellRendererComponent
                    (JTable table, Object button, boolean isSelected, boolean hasFocus, int row, int column) {
                return (JButton)button;
        class OldModel extends DefaultTableModel {
            public OldModel() {
                super(new String[][]{{"1","2"},{"3","4"}},new String[] {"1","2"});
        class MyModel extends AbstractTableModel {
            private String[] titles = { "A", "B" };
            private Object[][] summaryTable =
                    { new JButton("11"), new JButton("12") },
                    { new JButton("21"), new JButton("22") }
            public MyModel(){
                super();
            public int getColumnCount() {
                return titles.length;
            public String getColumnName(int col) {
                return titles[col];
            public int getRowCount() {
                return summaryTable.length;
            public Object getValueAt(int row, int col) {
                return summaryTable[row][col];
            public void setValueAt(Object value, int row, int column) {
                summaryTable[row][column] = value;
                fireTableCellUpdated(row, column);
            public Class getColumnClass(int c) {
                return getValueAt(0, c).getClass();
            public boolean isCellEditable(int row, int col) {
                return true;
    }

  • Jbutton below JTable in the same frame

    Hi All,
    I want to display a button below the JTable as shown below.
    [http://s361.photobucket.com/albums/oo52/ufucker_ufaggot/?action=view&current=untitled.jpg]
    Here is my code:
    Jbutton savebuton = new Jbutton("save");
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    JScrollPane scrollPane = new JScrollPane(table);
    frame.getContentPane().add(scrollPane);
    frame.setVisible(true);
    frame.validate();How should i add savebutton to the frame to get the desired result.
    Regards

    OK - must admit that I had neglected to look at the screenshot. But yuck that is horrid, what is the point of all that blank space?
    In any case, putting the elements in a(nother) JPanel and setting an EmptyBorder to it can provide all that wasted space. Here is an example of that, for the button. Play with the numbers until you are happy with the result.
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.border.*;
    class TwoElementsInFrame {
      public static void main(String[] args) {
        JFrame frame = new JFrame("TwoElementsInFrame");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        JButton savebuton = new JButton("save");
        JPanel savePanel = new JPanel();
        savePanel.setBorder( new EmptyBorder(50,200,50,5) );
        savePanel.add( savebuton );
        JPanel panel = new JPanel(new BorderLayout(5,5));
        panel.add(savePanel, BorderLayout.SOUTH);
        JTable table = new JTable();
        table.setPreferredScrollableViewportSize(new Dimension(500, 70));
        JScrollPane scrollPane = new JScrollPane(table);
        panel.add(scrollPane, BorderLayout.CENTER);
        frame.getContentPane().add(panel);
        frame.setVisible(true);
        frame.validate();
        frame.pack();
        frame.setVisible(true);
    }

  • Add a JButton to JTable

    hi all,
    I want to add a Jbutton in to a cell in a Jtable. the JButton's width shold be less than the width of the cell. can anyone tell me hw 2 do dat?
    thx in advance

    Use a JPanel as the renderer/editor. Add the JButton to the JPanel.Why would you use a JPanel as a renderer and add a JButton to the panel?
    Whats wrong with just using a JButton as the renderer/editor?
    The solution is not as easy as you make it sound anytime you need your component to respond to mouse events.

  • Placing JButtons in JTable cells

    I would like to place JButtons in one column of a JTable.
    Can anyone post or point me toward some example code that illustrates this?
    Many thanks in advance.

    did you try this with the cell renderer
    This should work. Try extending the DefaultCellRenderer and set them as a jbutton
    hope this will work

  • JButton in table cell in Find Mode

    Hello!
    I have JButton in JTable cell for calling LOV.
    When form goes to Find Mode all JButtons become disabled.
    Accordingly, I want that buttons active. Any help will be appreciated %)

    If the button is bound with an LOV Button binding, then I believe the framework checks the queryable property of the "target" attribute. Make sure that attribute has the "queryable" property checked in the View/Entity.
    Hope this helps.
    Erik

  • Problem in JTable,Kindly help very urgent

    I am trying to add /remove rows from JTable whose first column is JButton and others are JComboBox's.If no rows are selected,new row is added at the end.If user selects some row & then presses insert button,new row is added below it.Rows can only be deleted if user has made some selection.I am also using Icon for the button of currently active row.But i am getting exception(ArrayIndexBounds)when i try to add/delete.May be proper refreshing is not taking place.Kindly help me,where i am making mistake.If any function is to be used.My code is as follows....It is running code
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    import java.util.*;
    public class JButtonTableExample extends JFrame implements ActionListener,TableModelListener
    JComboBox mComboLHSType = new JComboBox();
    JComboBox mComboRHSType = new JComboBox();
    JLabel mLabelLHSType = new JLabel("LHS Type");
    JLabel mLabelRHSType = new JLabel("RHS Type");
    JButton mButtonDelete = new JButton("Delete");
    JButton mButtonInsert = new JButton("Insert");
    JButton check = new JButton("check");
    JPanel mPanelButton = new JPanel();
    JPanel mPanelScroll = new JPanel();
    JPanel mPanelCombo = new JPanel();
    DefaultTableModel dm ;
    TableColumnModel modelCol;
    JTable table;
    JScrollPane scroll;
    int currentRow = -1;
    static int mSelectedRow = -1;
    EachRowEditor rowEditor;
    public JButtonTableExample()
    super( "JButtonTable Example" );
    makeForm();
    setSize( 410, 222 );
    setVisible(true);
    private void makeForm()
         this.getContentPane().setLayout(null);
         mLabelLHSType.setBounds(new Rectangle(26,5,71,22));
         mComboLHSType.setBounds(new Rectangle(83,5,100,22));
         mLabelRHSType.setBounds(new Rectangle(232,5,71,22));
         mComboRHSType.setBounds(new Rectangle(292,5,100,22));
         mPanelCombo.setLayout(null);
         mPanelCombo.setBorder(new LineBorder(Color.red));
         mPanelCombo.setBounds(new Rectangle(1,1,400,30));
         mComboRHSType.addItem("Constant");
    mComboRHSType.addItem("Variable");
    mComboRHSType.setSelectedIndex(0);
    mComboRHSType.addActionListener(this);
    mPanelCombo.add(mLabelLHSType,null);
    mPanelCombo.add(mComboLHSType,null);
    mPanelCombo.add(mLabelRHSType,null);
    mPanelCombo.add(mComboRHSType,null);
         mPanelButton.setLayout(null);
         mPanelButton.setBorder(new LineBorder(Color.green));
         mPanelButton.setBounds(new Rectangle(1,165,400,30));
         mButtonInsert.setBounds(new Rectangle(120,5,71,22));
         mButtonDelete.setBounds(new Rectangle(202,5,71,22));
         mButtonDelete.addActionListener(this);
    mButtonInsert.addActionListener(this);
    check.setBounds(new Rectangle(3,3,71,22));
    check.addActionListener(this);
    mPanelButton.add(mButtonDelete,null);
    mPanelButton.add(mButtonInsert,null);
    mPanelButton.add(check,null);
         dm = new DefaultTableModel()
              public boolean isCellEditable(int row, int col)
              if(row == 0 && col ==1)
                   return false;
              return true;
         dm.addTableModelListener(this);
         //dm.setDataVector(null,
                             //new Object[]{"Button","Join","LHS","Operator","RHS"});
         dm.setDataVector(new Object[][]{{"","","","",""}},
                             new Object[]{"","Join","LHS","Operator","RHS"});
         table = new JTable(dm);
         table.getTableHeader().setReorderingAllowed(false);
         table.setRowHeight(25);
         table.setRowSelectionInterval(0,0);
         rowEditor = new EachRowEditor(table);
         int columnWidth[] = {20,45,95,95,95};
         mPanelScroll.setLayout(null);
         mPanelScroll.setBorder(new LineBorder(Color.blue));
         mPanelScroll.setBounds(new Rectangle(1,28,400,135));
         scroll = new JScrollPane(table);
    scroll.setBounds(new Rectangle(1,1,400,133));
    mPanelScroll.add(scroll,null);
         modelCol = table.getColumnModel();
         for (int i=0;i<5;i++)
         modelCol.getColumn(i).setPreferredWidth(columnWidth);
         setCellTypes();
    this.getContentPane().add(mPanelCombo,null);
    this.getContentPane().add(mPanelScroll,null);
    this.getContentPane().add(mPanelButton,null);
    }//end of makeForm()
    private void setCellTypes()
         modelCol.getColumn(0).setCellRenderer(new ButtonCR());
         modelCol.getColumn(0).setCellEditor(new ButtonCE(new JCheckBox()));
         modelCol.getColumn(0).setResizable(false);
         setUpJoinColumn(modelCol.getColumn(1));
         setUpLHSColumn(modelCol.getColumn(2));
         setUpOperColumn(modelCol.getColumn(3));
         setUpRHSColumn(modelCol.getColumn(4));//By Default contains JTextField
    public void actionPerformed(ActionEvent ae)
         if (ae.getSource() == mButtonInsert)
              int currentRow = table.getSelectedRow();
              if(currentRow == -1)
                   int rowCount = dm.getRowCount();
                   if(rowCount == 0)
                        table.clearSelection();
                        dm.insertRow(0,new Object[]{"","","","",""});
                        mComboRHSType.setEnabled(true);
                        mButtonDelete.setEnabled(true);
                        dm.fireTableDataChanged();
                        table.setRowSelectionInterval(0,0);
                   else
                        table.clearSelection();
                        dm.insertRow(rowCount,new Object[]{"","","","",""});
                        dm.fireTableDataChanged();
                        table.setRowSelectionInterval(rowCount,rowCount);
              else
                   table.clearSelection();
                   dm.insertRow(currentRow+1,new Object[]{"","","","",""});
                   dm.fireTableDataChanged();
                   table.setRowSelectionInterval(currentRow+1,currentRow+1);
    if(table.getRowCount()>0)
         table.setValueAt(new String(""),0,1);
         if(ae.getSource() == mButtonDelete)
    int currentRow = table.getSelectedRow();
    if(currentRow != -1)
    table.clearSelection();
                   dm.removeRow(currentRow);
                   if(dm.getRowCount() == 0)
                        mComboRHSType.setEnabled(false);
                        mButtonDelete.setEnabled(false);
                   dm.fireTableDataChanged();
              else
              JOptionPane.showMessageDialog(null, "Select row first", "alert", JOptionPane.ERROR_MESSAGE);
    //always the first cell is empty and disabled
    if(table.getRowCount()>0)
         table.setValueAt(new String(""),0,1);
         if(ae.getSource() == check)
              int r = table.getSelectedRow();
              for(int i=1;i<5;i++)
                   Object obj = table.getValueAt(r,i);
                   System.out.println("Value is"+obj.toString());
         if(ae.getSource()==mComboRHSType)
              System.out.println(mComboRHSType.getSelectedItem().toString());
              if(table.getSelectedRow() == -1)
                        JOptionPane.showMessageDialog(null, "Select row first", "alert", JOptionPane.ERROR_MESSAGE);
                        mComboRHSType.setSelectedIndex(0);
                   else
                        if((mComboRHSType.getSelectedItem().toString()).equalsIgnoreCase("Constant"))
                             rowEditor.stopCellEditing();
                             table.setValueAt("",table.getSelectedRow(),4);
                             rowEditor.setEditorAt(table.getSelectedRow(), new DefaultCellEditor(new JTextField()));
                             table.getColumn("RHS").setCellEditor(rowEditor);
                        else if((mComboRHSType.getSelectedItem().toString()).equalsIgnoreCase("Variable"))
                        JComboBox comboBox = new JComboBox();
                        comboBox.addItem("Variable1");
                        comboBox.addItem("Constant1");
                        comboBox.addItem("Constant2");
                        rowEditor.stopCellEditing();
                        table.setValueAt("",table.getSelectedRow(),4);
                        rowEditor.setEditorAt(table.getSelectedRow(), new DefaultCellEditor(comboBox));
                        table.getColumn("RHS").setCellEditor(rowEditor);
    }//end of actionPerformed()
    public void tableChanged(TableModelEvent e)
              if(e.getType()==e.DELETE)
                   System.out.println("DELETE CALEED called##################)");
              if(e.getType()==e.INSERT)
                   System.out.println("INSERT CALEED called##################)");
    public void setUpJoinColumn(TableColumn joinColumn)
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("AND");
    comboBox.addItem("OR");
    comboBox.addItem("NOT");
    joinColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    joinColumn.setCellRenderer(renderer);
    //Set up tool tip for the header.
    TableCellRenderer headerRenderer = joinColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer)
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText("Click to see list of Join Conditions");
    public void setUpLHSColumn(TableColumn LHSColumn)
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Participant1");
    comboBox.addItem("Participant2");
    comboBox.addItem("Variable1");
    LHSColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    LHSColumn.setCellRenderer(renderer);
    //Set up tool tip for the header.
    TableCellRenderer headerRenderer = LHSColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer)
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText("Click the sport to see Participants or Variables");
    public void setUpOperColumn(TableColumn operColumn)
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("=");
    comboBox.addItem("!=");
    comboBox.addItem("Contains");
    operColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    operColumn.setCellRenderer(renderer);
    //Set up tool tip for header.
    TableCellRenderer headerRenderer = operColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer)
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click to see a list of operators");
    public void setUpRHSColumn(TableColumn rhsColumn)
              rowEditor.setEditorAt(table.getSelectedRow(), new DefaultCellEditor(new JTextField()));
              rhsColumn.setCellEditor(rowEditor);
    //Set up tool tips
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    rhsColumn.setCellRenderer(renderer);
    public static void main(String[] args)
    JButtonTableExample frame = new JButtonTableExample();
    frame.addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    }//end of program
    //Button as a renderer for the table cells
    class ButtonCR implements TableCellRenderer
         JButton btnSelect;
         public ButtonCR()
              btnSelect = new JButton();
              btnSelect.setMargin(new Insets(0,0,0,0));
         public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column)
              if (column != 0) return null; //meany !!!
              return btnSelect;
    }//end fo ButtonCR
    //Default Editor for table
    class ButtonCE extends DefaultCellEditor implements ActionListener
         JButton btnSelect;
         JTable table;
         static int selectedRow = -1;
         public ButtonCE(JCheckBox whoCares)
              super(whoCares);
              btnSelect = new JButton();
              btnSelect.setMargin(new Insets(0,0,0,0));
              btnSelect.addActionListener(this);
              setClickCountToStart(1);
         public Component getTableCellEditorComponent(JTable     table,Object value,boolean isSelected,int row,int column)
              if (column != 0) return null; //meany !!!
              this.selectedRow = row;
              this.table = table;
              System.out.println("Inside getTableCellEditorComponent");
              return btnSelect;
         //public Object getCellEditorValue()
              //return val;
         public void actionPerformed(ActionEvent e)
              // Your Code Here...
              System.out.println("Inside actionPerformed");
              System.out.println("Action performed Row selected "+selectedRow);
              btnSelect.setIcon(new ImageIcon("capsigma.gif"));
    }//end of ButtonCE
    class EachRowEditor implements TableCellEditor
         protected Hashtable editors;
    protected TableCellEditor editor, defaultEditor;
    JTable table;
    * Constructs a EachRowEditor.
    * create default editor
    * @see TableCellEditor
    * @see DefaultCellEditor
    public EachRowEditor(JTable table)
              this.table = table;
         editors = new Hashtable();
         defaultEditor = new DefaultCellEditor(new JTextField());
         editor = defaultEditor;
         * @param row table row
         * @param editor table cell editor
         public void setEditorAt(int row, TableCellEditor editor)
         editors.put(new Integer(row),editor);
    public Component getTableCellEditorComponent(JTable table,Object value, boolean isSelected, int row, int column)
         //editor = (TableCellEditor)editors.get(new Integer(row));
         //if (editor == null)
         //     editor = defaultEditor;
         return editor.getTableCellEditorComponent(table,value, isSelected, row, column);
         public Object getCellEditorValue()
         System.out.println("getCellEditoeValue");
         return editor.getCellEditorValue();
         public boolean stopCellEditing()
         System.out.println("stopCellEditing");
         return editor.stopCellEditing();
         public void cancelCellEditing()
         System.out.println("cancelCellEditing");
         editor.cancelCellEditing();
    public boolean isCellEditable(EventObject anEvent)
    System.out.println("isCellEditable");
    selectEditor((MouseEvent)anEvent);
    return editor.isCellEditable(anEvent);
    public void addCellEditorListener(CellEditorListener l)
    System.out.println("addCellEditorListener");
    editor.addCellEditorListener(l);
    public void removeCellEditorListener(CellEditorListener l)
         System.out.println("removeCellEditorListener");
    editor.removeCellEditorListener(l);
    public boolean shouldSelectCell(EventObject anEvent)
    System.out.println("shouldSelect");
    selectEditor((MouseEvent)anEvent);
    return editor.shouldSelectCell(anEvent);
    protected void selectEditor(MouseEvent e) {
    int row;
    if (e == null) {
    row = table.getSelectionModel().getAnchorSelectionIndex();
    } else {
    row = table.rowAtPoint(e.getPoint());
    editor = (TableCellEditor)editors.get(new Integer(row));
    if (editor == null) {
    editor = defaultEditor;
    }//end of EachRowEditor

    Hello!
    Catch the exception in your event handler:
    try {
    } catch(Exception ex) { ex.printStackTrace(); }
    You can now isolate the wrong line ^;
    Next time if you post such a large code please use code and /code
    enclosed in brackets : []; (See http://forum.java.sun.com/faq.jsp#format)
    class A extends B {
          public void niceCode() {

  • Problem in adding/deleting rows in JTable

    I am trying to add /remove rows from JTable whose first column is JButton and others are JComboBox's.If no rows are selected,new row is added at the end.If user selects some row & then presses insert button,new row is added below it.Rows can only be deleted if user has made some selection.Kindly help me,where i am making mistake.If any function is to be used.My code is as follows....
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    public class JButtonTableExample extends JFrame implements ActionListener{
    JComboBox mComboLHSType = new JComboBox();
    JComboBox mComboRHSType = new JComboBox();
    JLabel mLabelLHSType = new JLabel("LHS Type");
    JLabel mLabelRHSType = new JLabel("RHS Type");
    JButton mButtonDelete = new JButton("Delete");
    JButton mButtonInsert = new JButton("Insert");
    JPanel mPanelButton = new JPanel();
    JPanel mPanelScroll = new JPanel();
    JPanel mPanelCombo = new JPanel();
    DefaultTableModel dm ;
    JTable table;
    int currentRow = -1;
    static int mSelectedRow = -1;
    public JButtonTableExample()
    super( "JButtonTable Example" );
    makeForm();
    setSize( 410, 222 );
    setVisible(true);
    private void makeForm()
    this.getContentPane().setLayout(null);
    mPanelCombo.setLayout(null);
    mPanelCombo.setBorder(new LineBorder(Color.red));
    mPanelCombo.setBounds(new Rectangle(1,1,400,30));
    mLabelLHSType.setBounds(new Rectangle(26,5,71,22));
    mComboLHSType.setBounds(new Rectangle(83,5,100,22));
    mLabelRHSType.setBounds(new Rectangle(232,5,71,22));
    mComboRHSType.setBounds(new Rectangle(292,5,100,22));
    mPanelCombo.add(mLabelLHSType,null);
    mPanelCombo.add(mComboLHSType,null);
    mPanelCombo.add(mLabelRHSType,null);
    mPanelCombo.add(mComboRHSType,null);
    mPanelScroll.setLayout(null);
    mPanelScroll.setBorder(new LineBorder(Color.blue));
    mPanelScroll.setBounds(new Rectangle(1,28,400,135));
    mPanelButton.setLayout(null);
    mPanelButton.setBorder(new LineBorder(Color.green));
    mPanelButton.setBounds(new Rectangle(1,165,400,30));
    mButtonInsert.setBounds(new Rectangle(120,5,71,22));
    mButtonDelete.setBounds(new Rectangle(202,5,71,22));
    mButtonDelete.addActionListener(this);
    mButtonInsert.addActionListener(this);
    mPanelButton.add(mButtonDelete,null);
    mPanelButton.add(mButtonInsert,null);
    dm = new DefaultTableModel();
    //dm.setDataVector(null,
    //new Object[]{"Button","Join","LHS","Operator","RHS"});
    dm.setDataVector(new Object[][]{{"","","","",""}},
    new Object[]{"","Join","LHS","Operator","RHS"});
    table = new JTable(dm);
    table.getTableHeader().setReorderingAllowed(false);
    table.setRowHeight(25);
    int columnWidth[] = {20,45,95,95,95};
    TableColumnModel modelCol = table.getColumnModel();
    for (int i=0;i<5;i++)
    modelCol.getColumn(i).setPreferredWidth(columnWidth);
    //modelCol.getColumn(0).setCellRenderer(new ButtonRenderer());
    //modelCol.getColumn(0).setCellEditor(new ButtonEditor(new JCheckBox()));
    modelCol.getColumn(0).setCellRenderer(new ButtonCR());
    modelCol.getColumn(0).setCellEditor(new ButtonCE(new JCheckBox()));
    modelCol.getColumn(0).setResizable(false);
    setUpJoinColumn(modelCol.getColumn(1));
    setUpLHSColumn(modelCol.getColumn(2));
    setUpOperColumn(modelCol.getColumn(3));
    setUpRHSColumn(modelCol.getColumn(4));
    JScrollPane scroll = new JScrollPane(table);
    scroll.setBounds(new Rectangle(1,1,400,133));
    mPanelScroll.add(scroll,null);
    this.getContentPane().add(mPanelCombo,null);
    this.getContentPane().add(mPanelScroll,null);
    this.getContentPane().add(mPanelButton,null);
    }//end of makeForm()
    public void actionPerformed(ActionEvent ae)
    if (ae.getSource() == mButtonInsert)
    //int currentRow = table.getSelectedRow();
    currentRow = ButtonCE.selectedRow;
    System.out.println("Before Insert CURRENT ROW"+currentRow);
    if(currentRow == -1)
    int rowCount = dm.getRowCount();
    //mSelectedRow = rowCount-1;
    //table.clearSelection();
    dm.insertRow(rowCount,new Object[]{"","","","",""});
    currentRow = -1;
    ButtonCE.selectedRow = -1;
    else
    table.clearSelection();
    dm.insertRow(currentRow+1,new Object[]{"","","","",""});
    currentRow = -1;
    ButtonCE.selectedRow = -1;
    //System.out.println("After INSERT CURRENT ROW"+currentRow);
    if(ae.getSource() == mButtonDelete)
    //int currentRow = table.getSelectedRow();
    currentRow = ButtonCE.selectedRow;
    System.out.println("Before DELETE CURRENT ROW"+currentRow);
    if(currentRow != -1)
    dm.removeRow(currentRow);
    table.clearSelection();
    currentRow = -1;
    ButtonCE.selectedRow = -1;
    //System.out.println("Selected Row"+mSelectedRow);
    else
    JOptionPane.showMessageDialog(null, "Select row first", "alert", JOptionPane.ERROR_MESSAGE);
    //System.out.println("DELETE CURRENT ROW"+currentRow);
    public void setUpJoinColumn(TableColumn joinColumn)
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("AND");
    comboBox.addItem("OR");
    comboBox.addItem("NOT");
    joinColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer =
    new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    joinColumn.setCellRenderer(renderer);
    //Set up tool tip for the sport column header.
    TableCellRenderer headerRenderer = joinColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the sport to see a list of choices");
    public void setUpLHSColumn(TableColumn LHSColumn)
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Participant1");
    comboBox.addItem("Participant2");
    comboBox.addItem("Variable1");
    LHSColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer =
    new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    LHSColumn.setCellRenderer(renderer);
    //Set up tool tip for the sport column header.
    TableCellRenderer headerRenderer = LHSColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the sport to see a list of choices");
    public void setUpOperColumn(TableColumn operColumn)
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("=");
    comboBox.addItem("!=");
    comboBox.addItem("Contains");
    operColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer =
    new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    operColumn.setCellRenderer(renderer);
    //Set up tool tip for the sport column header.
    TableCellRenderer headerRenderer = operColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the sport to see a list of choices");
    public void setUpRHSColumn(TableColumn rhsColumn)
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Variable1");
    comboBox.addItem("Constant1");
    comboBox.addItem("Constant2");
    rhsColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer =
    new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    rhsColumn.setCellRenderer(renderer);
    //Set up tool tip for the sport column header.
    TableCellRenderer headerRenderer = rhsColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the sport to see a list of choices");
    public static void main(String[] args) {
    JButtonTableExample frame = new JButtonTableExample();
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    //Button as a renderer for the table cells
    class ButtonCR implements TableCellRenderer
    JButton btnSelect;
    public ButtonCR()
    btnSelect = new JButton();
    btnSelect.setMargin(new Insets(0,0,0,0));
    public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column)
    if (column != 0) return null; //meany !!!
    //System.out.println("Inside renderer########################Selected row");
    //btnSelect.setText(value.toString());
    //btnSelect.setIcon(new ImageIcon("capsigma.gif"));
    return btnSelect;
    }//end fo ButtonCR
    //Default Editor for table
    class ButtonCE extends DefaultCellEditor implements ActionListener
    JButton btnSelect;
    JTable table;
    //Object val;
    static int selectedRow = -1;
    public ButtonCE(JCheckBox whoCares)
    super(whoCares);
    //this.row = row;
    btnSelect = new JButton();
    btnSelect.setMargin(new Insets(0,0,0,0));
    btnSelect.addActionListener(this);
    setClickCountToStart(1);
    public Component getTableCellEditorComponent(JTable table,Object value,boolean isSelected,int row,int column)
    if (column != 0) return null; //meany !!!
    this.selectedRow = row;
    this.table = table;
    table.clearSelection();
    System.out.println("Inside getTableCellEditorComponent");
    return btnSelect;
    //public Object getCellEditorValue()
    //return val;
    public void actionPerformed(ActionEvent e)
    // Your Code Here...
    System.out.println("Inside actionPerformed");
    System.out.println("Action performed Row selected "+selectedRow);
    btnSelect.setIcon(new ImageIcon("capsigma.gif"));
    }//end of ButtonCE

    Hi,
    All the thing you have to do is to return a boolean for the column. JTable will use a checkbox (as default) to show boolean values.

Maybe you are looking for