This discussion is archived
7 Replies Latest reply: Oct 7, 2004 6:19 AM by 807587 RSS

Adding jcheckbox in to and getvalues.

807587 Newbie
Currently Being Moderated
I want to add a JCheckBox into JTable .When checkbox will clicked then to get specific colums values.
Suppose when checkbox will be checked then to get the values of column no three.Anybody can help we with a small example.Please anybody do it must , i need it urgently.

Regards
  • 1. Re: Adding jcheckbox in to and getvalues.
    807587 Newbie
    Currently Being Moderated
    Try making the class for that column Boolean.class.
  • 2. Re: Adding jcheckbox in to and getvalues.
    807587 Newbie
    Currently Being Moderated
    I don't have any idea what i have to do.i wish to add jcheckboxes in entire column and when checkbos will be checked then diaplay all table in that row.Can u do it for me?
  • 3. Re: Adding jcheckbox in to and getvalues.
    807587 Newbie
    Currently Being Moderated
    I don't have any idea what i have to do.i wish to add jcheckboxes in entire column and when checkbos will be checked then diaplay all table in that row.Can u do it for me?
  • 4. Re: Adding jcheckbox in to and getvalues.
    807587 Newbie
    Currently Being Moderated
    These forums are here primarily to answer questions, not to get someone else to write your code for you.
    Post some code and a specific question and perhaps a forum member will answer you.
  • 5. Re: Adding jcheckbox in to and getvalues.
    807587 Newbie
    Currently Being Moderated
    I don't have any idea what i have to do.i wish to add jcheckboxes in entire column and when checkbos will be checked then display all values in that row.Can any do it for me? plz write a complete code example.
  • 6. Re: Adding jcheckbox in to and getvalues.
    807587 Newbie
    Currently Being Moderated
    I suggest you read the JTable tutorial.
  • 7. Re: Adding jcheckbox in to and getvalues.
    807587 Newbie
    Currently Being Moderated
    here is code in which i want to add checkbox and when checkbox will be clicked.to get that all row values.
    this code also generates IndexoutOfBoundsException when compiled.Plz help in this regard.

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import javax.swing.table.*;
    import java.util.*;
    public class Tedit extends JFrame {
    Container con;
    JTable table;
    JScrollPane sp;
    public Tedit(){

    super("Table With ComboBox");
    con =this.getContentPane();

    Vector column=new Vector();
    column.addElement("Select");
    column.addElement("Name");
    column.addElement("Class");
    column.addElement("City");

    Vector rows=new Vector();
    rows.addElement("Food");
    rows.addElement("Waheed");
    rows.addElement("BCS-8");
    rows.addElement("Gojra");

    TableModel model = new EditableTableModel(column,rows);
    table = new JTable(model);
    table.createDefaultColumnsFromModel();
    con.add(new JScrollPane(table));
    setSize(400,400);
    setVisible(true);
    }
    public static void main(String args[]){
    Tedit te = new Tedit();
    }
    } class EditableTableModel extends AbstractTableModel{
    Vector col;
    Vector rows;
    int rowCount;
    public EditableTableModel(Vector col,Vector rows){
    this.col=col;
    this.rows=rows;
    }
    public int getRowCount(){
    return rows.capacity();
    }
    public int getColumnCount(){
    return col.capacity();
    }
    public Object getValueAt(int row, int column){
    return "Waheed";
    }
    public String getColumnName(int column){
    return (String) col.elementAt(column);
    }
    public boolean isCellEditable(int row, int column){
    return true;
    }
    }