Adding JCheckBox into JTable

Hi all,
I added a JCheckBox into a JTable, while clicking the check box the selection will not replicate into the JTable. Please help me to resolve this issue.
* TableDemo.java
* Created on September 5, 2006, 11:49 AM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package simPackage;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.*;
* @author aathirai
public class TableDemo extends JPanel{
   // public JRadioButton[] dataButton;
    /** Creates a new instance of TableDemo */
    public TableDemo() {
        JCheckBox firstCheck = new JCheckBox("");
        Object[][] data={{firstCheck,"2","4","5","2"}};
                String[] columnNames={"qr No","supplier kt code","part no","start date","end date"};
                JTable searchResultTable = new JTable(data,columnNames);
                searchResultTable.getColumn("qr No").setCellRenderer(new RadioButtonRenderer());
                searchResultTable.getColumn("qr No").setCellEditor(new RadioButtonEditor(firstCheck));
        JScrollPane scrollPane = new JScrollPane(searchResultTable);
        //Add the scroll pane to this panel.
        add(scrollPane);
public static void main(String args[])   {
     JFrame jFrame  = new JFrame("testing");
     jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Create and set up the content pane.
        TableDemo newContentPane = new TableDemo();
        newContentPane.setOpaque(true); //content panes must be opaque
        jFrame.setContentPane(newContentPane);
        //Display the window.
        jFrame.pack();
        jFrame.setVisible(true);
class RadioButtonRenderer implements TableCellRenderer {
    public JCheckBox check1 = new JCheckBox("");
  public Component getTableCellRendererComponent(JTable table, Object value,
   boolean isSelected, boolean hasFocus, int row, int column) {
      check1.setBackground(Color.WHITE);
     return check1;
class RadioButtonEditor extends DefaultCellEditor{
    public JCheckBox check1 = new JCheckBox("");
  boolean state;
  int r, c;
  JTable t;
  class RbListener implements ActionListener{
    public void actionPerformed(ActionEvent e){
      if (e.getSource() == check1){
        state = true;
      else{
        state = false;
      RadioButtonEditor.this.fireEditingStopped();
  public RadioButtonEditor(JCheckBox checkBox) {
    super(checkBox);
  public Component getTableCellEditorComponent(JTable table, Object value,
   boolean isSelected, int row, int column) {
    RbListener rb = new RbListener();
    t = table;
    r = row;
    c = column;
    if (value == null){
      return null;
    check1.addActionListener(rb);
     //check1.setSelected(((Boolean)value).booleanValue());
    /*if (((Boolean)value).booleanValue() == true){
      check1.setSelected(true);
    return check1;
  public Object getCellEditorValue() {
    if (check1.isSelected() == true){
      return Boolean.valueOf(true);
    else{
      return Boolean.valueOf(false);
}Thanks in advance.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
class TableDemo extends JPanel
  public TableDemo()
    //JCheckBox firstCheck = new JCheckBox("");
    //Object[][] data={{firstCheck,"2","4","5","2"}};
    Object[][] data={{new Boolean(false),"2","4","5","2"}};
    String[] columnNames={"qr No","supplier kt code","part no","start date","end date"};
    JTable searchResultTable = new JTable(data,columnNames);
    //searchResultTable.getColumn("qr No").setCellRenderer(new RadioButtonRenderer());
    //searchResultTable.getColumn("qr No").setCellEditor(new RadioButtonEditor(firstCheck));
    TableColumn tc = searchResultTable.getColumnModel().getColumn(0);
    tc.setCellEditor(searchResultTable.getDefaultEditor(Boolean.class));
    tc.setCellRenderer(searchResultTable.getDefaultRenderer(Boolean.class));
    JScrollPane scrollPane = new JScrollPane(searchResultTable);
    add(scrollPane);
  public static void main(String args[])
    JFrame jFrame  = new JFrame("testing");
    jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    TableDemo newContentPane = new TableDemo();
    newContentPane.setOpaque(true); //content panes must be opaque
    jFrame.setContentPane(newContentPane);
    jFrame.pack();
    jFrame.setVisible(true);
}

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 .....

  • Adding JcheckBox in JTable

    Hi there,
    I have a JcheckBox in a JTable. Whenever I click the Checkbox , on that particular cell it display true , when Clicked and false when I click again. Is there any way that I could disable that ?, I also wanted to center the Jcheckbox ?
    Thanks

    Similar way I'm using in other class & it is working.But a JTable is not the same as other components, which is why you should be using Boolean values.
    You responded to my post 12 minutes after I posted my reply. That did not give you enough time to read the tutorial and understand how to use a JTable correctly!!!

  • Booleans not rendering as JCheckBoxes in JTable

    I've read several posts on trying to get JCheckBoxes to render in a JTable, and I've looked at the Tables tutorial, but I still can't figure out why my JTable isn't rendering Booleans as check-boxes. :-(
    I thought rendering check-boxes was the the default behavior for cells with Boolean values. This doesn't seem to be the case. I can add a cell editor of type JCheckBox by simply instantiating a new DefaultCellEditor, but adding a cell renderer doesn't look so easy (I believe I have to create my own implementation class). I was trying to avoid that, because a) I'm working in Servoy (which means I'm working in a Rhino editor and need to access my own custom classes as plugins or beans), and b) my Java skills are weak.
    So can anybody see anything about my code that is obviously wrong? Or do I have to roll up my sleeves and write my own DefaultTableCellRenderer bean/plugin?
    Here's my code (remember - it's javascript instances of java objects). (Note: I'm not sure exactly what kinds of objects JSDataSet.getAsTableModel() returns to the JTable model, but creating my own JTable with a vector of vectors of Boolean objects, or setting a Boolean in the cell after the fact doesn't work either.)
    Any tips would be greatly appreciated.
    // convert dataset into JTable
    var table = elements.monitoring;
    table.model = treatments.getAsTableModel();
    // modify column headers
    var columns = table.columnModel;
    columns.getColumn(0).setHeaderValue('Quantity');
    columns.getColumn(0).setPreferredWidth(60);
    columns.getColumn(1).setHeaderValue('Repeats/hr.');
    columns.getColumn(1).setPreferredWidth(75);
    columns.getColumn(2).setHeaderValue('TREATMENT');
    columns.getColumn(2).setPreferredWidth(225);
    // start treatment times at 8am
    var j=8;
    for (i=3;i<44;++i) {
         var j_int = Packages.java.lang.Integer(j);
         columns.getColumn(i).setHeaderValue(j_int);
         columns.getColumn(i).setPreferredWidth(10);
         if (j == 12) {
              j=0;
         ++j;
    // center cell data
    var cell_class = Packages.java.lang.String;
    var table_renderer = table.getDefaultRenderer(cell_class);
    table_renderer.setHorizontalAlignment(0);
    // add JTable to JScrollPane viewport (necessary to display headers)
    var viewport = elements.monitoring_pane.viewport;
    viewport.add(table);

    Ok, another problem -
    I wound up throwing out the Rhino constructor method and implementing my own JTable class and importing it into the Rhino scope. I had to do that because I needed columns to render different types of objects - basically, the table cells should appear blank until they are selected and data is added to them, at which point they should be Boolean and render check-boxes - I got that to work by overriding the getCellRenderer method.
    The problem is, I need to add some logic to the 'onClick' event for the table cell, so that I can add a blank check box, add a checked check box, or remove a check box. I looked at the Table tutorial and tried to do it by implementing the TableModelListener interface on my JTable and defining the tableChanged method. However, when I add the tableChanged method to my class, I get an ArrayIndexOutOfBoundsException.
    Any tips would be greatly appreciated.
    I instantiate the class in Rhino and add the TableModelListener like so:
    var table = new Packages.my_classes.MyJTable();
    table.model = model; // a working model defined elsewhere
    table.getModel().addTableModelListener(table);Here's my class:
    package my_classes;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    public class MyJTable extends JTable implements TableModelListener {
         public TableCellRenderer getCellRenderer(int row, int column) {
              Object value = getValueAt(row,column);
                if (value == null) {
                     return getDefaultRenderer(JCheckBox.class);
                return super.getCellRenderer(row,column);
         public Class getColumnClass(int column) {
              if (column > 2) {
                   return Boolean.class;
              } else {
                   return Object.class;
         public void tableChanged(TableModelEvent e) {
              int row = e.getFirstRow();
              int column = e.getColumn();
              TableModel model = (TableModel) e.getSource();
              String columnName = model.getColumnName(column);
              Object data = model.getValueAt(row, column);
    }

  • JckechBox into JTable -- getselectedrow

    I have a problem with Checkbox into JTable
    My table has checkbox into first column. If I select checkbox, the program open a new JPanel. To do this I have associated an ActionListener to CheckBox that seems to work fine. This is the related code:
    public class AbstractAction implements ActionListener{            
         private static final long serialVersionUID = 1L;     
        public void actionPerformed(ActionEvent evt) {
            JCheckBox cb = (JCheckBox)evt.getSource();
            alarm_NOack_table.getSelectedRow()
            boolean isSel = cb.isSelected();
            if (isSel) {
        } else {
       };As you can see, in the listener I need to know the row number in which there is the selected checkbox, but alarm_NOack_table.getSelectedRow() return always '-1'.
    How can I do?
    Thanks in advance
    Palmis

    hey!!!
    you will have to use TableModelListener
    if you have a look at API
    getSelectedRow()
    Returns the index of the first selected row, -1 if no row is selected.
    it says that only when row is selected. but clicking your check box does not select the whole row. so you need to listen for changes in the table itself. the best would be to write your own table model (extension of AbstractTableModel)
    this is how you should be able to get the change a your row where the change occurred
    public class YourClass implements TableModelListener{
    yourTable.getModel().addTableModelListener(this);
    public void tableChanged(TableModelEvent tme){
              int row = tme.getFirstRow();
              int col = tme.getColumn();
    //if you want your table model then do this
    TableModel tm = (TableModel)tme.getSource();
    }and now you should have the row a column where the change has occurred and that's it
    hope this will help
    v.v.

  • URGENT--inserting into JTable

    Hi
    i'm trying to insert data retrieved from the database into JTable
    i have seen some code examples on TableModel on this site but
    getting confused.Can anybody give me a full code example.
    Ashish

    you can take a look at the following link:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=357504
    I published my code for a dynamic table that supports adding/removing columns.

  • Cant get data from text file to print into Jtable

    Instead of doing JDBC i am using text file as database. I cant get data from text file to print into JTable when i click find button. Goal is to find a record and print that record only, but for now i am trying to print all the records. Once i get that i will change my code to search desired record and print it. when i click the find button nothing happens. Can you please take a look at my code, dbTest() method. thanks.
    void dbTest() {
    DataInputStream dis = null;
    String dbRecord = null;
    String hold;
    try {
    File f = new File("customer.txt");
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    dis = new DataInputStream(bis);
    Vector dataVector = new Vector();
    Vector headVector = new Vector(2);
    Vector row = new Vector();
    // read the record of the text database
    while ( (dbRecord = dis.readLine()) != null) {
    StringTokenizer st = new StringTokenizer(dbRecord, ",");
    while (st.hasMoreTokens()) {
    row.addElement(st.nextToken());
    System.out.println("Inside nested loop: " + row);
    System.out.println("inside loop: " + row);
    dataVector.addElement(row);
    System.out.println("outside loop: " + row);
    headVector.addElement("Title");
    headVector.addElement("Type");
    dataTable = new JTable(dataVector, headVector);
    dataTableScrollPane.setViewportView(dataTable);
    } catch (IOException e) {
    // catch io errors from FileInputStream or readLine()
    System.out.println("Uh oh, got an IOException error!" + e.getMessage());
    } finally {
    // if the file opened okay, make sure we close it
    if (dis != null) {
    try {
    dis.close();
    } catch (IOException ioe) {
    } // end if
    } // end finally
    } // end dbTest

    Here's a thread that loads a text file into a JTable:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=315172
    And my reply in this thread shows how you can use a text file as a simple database:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=342380

  • How do I stop itunes from automatically adding songs into my itunes library?

    I want to disable itunes from automatically adding songs into my library.  Every time I sync up my ipod I'm finding miscellaneous debris on it that itunes keeps importing into it.  Theres got to be a way to disable this function but I can't seem to find it in the preferences.   I'm using a 2011 macbook pro with os x 10.6.7. 

    I figured out how to change itunes as my default player.  I did this by selecting a new audio file and hitting cmd and I to get info, then I selected the "open with" category.  Inside "open with" theres an option to open the file with quick time, underneath that is the "change all" option.  select that and you will solve this problem if this is a nuisance to anyone else.

  • How to add data into JTable

    How can I add data into JTable, for instance ("Mike", "Gooler", 21).

    How can I add data into JTable, for instance ("Mike",
    "Gooler", 21).You will have very good results if you segregate out the table model as a seperate user class and provide a method to add a row there. In fact, if you use the table to reflect a database table you can add the row inplace using the existing cursor. I believe it's TableExample2 in the jdk\demo\jfc\TableExamples that has a very good example of this.
    Walt

  • Also problem read txt files into JTable

    hello,
    i used the following method to load a .txt file into JTable
    try{
                        FileInputStream fin = new FileInputStream(filename);
                        InputStreamReader isr = new InputStreamReader(fin);
                        BufferedReader br =  new BufferedReader(isr);
                        StringTokenizer st1 = new StringTokenizer(br.readLine(), "|");
                        while( st1.hasMoreTokens() )
                             columnNames.addElement(st1.nextToken());
                        while ((aLine = br.readLine()) != null)
                             StringTokenizer st2 = new StringTokenizer(aLine, "|");
                             Vector row = new Vector();
                             while(st2.hasMoreTokens())
                                  row.addElement(st2.nextToken());
                             data.addElement( row );
                        br.close();
                        }catch(Exception e){ e.printStackTrace(); }
                   //colNum = st1.countTokens();
                   model = new DefaultTableModel(data,columnNames);
                   table.setModel(model);but there is a problem : if cell A's location is (4,5),and its left neighbour,that is, cell(4,4) is blank (the value is ""), the the cell A's value will be displayed in cell(4,4).if cell(4,3) is also blank ,the cell A's value will be displayed in cell(4,3).that is,the non-blank value will be displayed in the first blank cell of the line.
    how can i solve it?Please give me some helps or links.
    Thank u very much!

    Or, use the String.split(..) method to tokenize the data
    Or, use my SimpleTokenizer class which you can find by using the search function.

  • Putting JCheckBox into JTreeTable

    I'm trying to place a JCheckBox into a JTreeTable and finding it to be far more difficult than I imagined. I want the first column in my JTreeTable to be uneditable while the next two columns have check boxes. If I use the JTreeTable III version, I can add a Boolean.class column which has checkboxes, but if I turn off the isCellEditable for the first column, the tree will not expand. If I use JTreeTable II version, I can add in a Boolean class for the checkbox field, but I can't make it editable, so the checkbox does not respond to mouse clicks.
    Any help would be appreciated. Thanks,
    Dan

    Thomas, are these the JTreeTables you are using or is there another version?no, i don't use those. i use some stuff which somebody published on http://www2.gol.com/users/tame/swing/examples. unfortunately that site doesn't exist anymore.
    but in general, it is not really difficult:
    1) put your tree in the row header view
    2) add a tree expansion listener
    3) upon treeExpanded() do a insertRow() on your table
    4) upon treeCollapse() do a deleteRow() on your table
    they only disadvantage i found is, that you can't resize the tree 'column'.
    thomas

  • Need to use vector to insert data into JTable?

    hi
    i'm trying to insert data from mssql 2000 into JTable. The number of columns are fixed, but the number of rows are not, since it will depend on how many data retrieved from the database.
    The documentation says that vector class implements a growable array of objects, and I've seen some examples using vector such as from http://forum.java.sun.com/thread.jspa?forumID=57&threadID=238597 .
    I would like to know, in my case, do i need to set my column and row to use vector? or should i only set rows to use vector ? (since the row size will vary, while the column size will stick to 6).

    Because your JTable operation will be done on a table model, the selection of the initial data
    structure for the model is almost non-issue. In other words, whatever will do.
    See the javadoc for the DefaultTableModel class, which you will eventually use, especially the
    construcotr part.

  • Cluster Storage : All SAN drives are not added up into cluster storage.

    Hi Team,
    Everything seems to be working fine except one minor issue which is one of the disk not showing in cluster storage even validation was without any issue, error or warning. Please see the report
    below where all SAN disks are validate successfully, and not added into Window Server 2012 storage.
    Quorum disk was added successfully into storage, but data disk was not.
    http://goldteam.co.uk/download/cluster.mht
    Thanks,
    SZafar

    Create Cluster
    Cluster:
    mail
    Node:
    MailServer-N2.goldteam.co.uk
    Node:
    MailServer-N1.goldteam.co.uk
    Quorum:
    Node and Disk Majority (Cluster Disk 1)
    IP Address:
    192.168.0.4
    Started
    12/01/2014 04:34:45
    Completed
    12/01/2014 04:35:08
    Beginning to configure the cluster mail.
    Initializing Cluster mail.
    Validating cluster state on node MailServer-N2.goldteam.co.uk.
    Find a suitable domain controller for node MailServer-N2.goldteam.co.uk.
    Searching the domain for computer object 'mail'.
    Bind to domain controller \\GTMain.goldteam.co.uk.
    Check whether the computer object mail for node MailServer-N2.goldteam.co.uk exists in the domain. Domain controller \\GTMain.goldteam.co.uk.
    Computer object for node MailServer-N2.goldteam.co.uk does not exist in the domain.
    Creating a new computer account (object) for 'mail' in the domain.
    Check whether the computer object MailServer-N2 for node MailServer-N2.goldteam.co.uk exists in the domain. Domain controller \\GTMain.goldteam.co.uk.
    Creating computer object in organizational unit CN=Computers,DC=goldteam,DC=co,DC=uk where node MailServer-N2.goldteam.co.uk exists.
    Create computer object mail on domain controller \\GTMain.goldteam.co.uk in organizational unit CN=Computers,DC=goldteam,DC=co,DC=uk.
    Check whether the computer object mail for node MailServer-N2.goldteam.co.uk exists in the domain. Domain controller \\GTMain.goldteam.co.uk.
    Configuring computer object 'mail in organizational unit CN=Computers,DC=goldteam,DC=co,DC=uk' as cluster name object.
    Get GUID of computer object with FQDN: CN=MAIL,CN=Computers,DC=goldteam,DC=co,DC=uk
    Validating installation of the Network FT Driver on node MailServer-N2.goldteam.co.uk.
    Validating installation of the Cluster Disk Driver on node MailServer-N2.goldteam.co.uk.
    Configuring Cluster Service on node MailServer-N2.goldteam.co.uk.
    Validating installation of the Network FT Driver on node MailServer-N1.goldteam.co.uk.
    Validating installation of the Cluster Disk Driver on node MailServer-N1.goldteam.co.uk.
    Configuring Cluster Service on node MailServer-N1.goldteam.co.uk.
    Waiting for notification that Cluster service on node MailServer-N2.goldteam.co.uk has started.
    Forming cluster 'mail'.
    Adding cluster common properties to mail.
    Creating resource types on cluster mail.
    Creating resource group 'Cluster Group'.
    Creating IP Address resource 'Cluster IP Address'.
    Creating Network Name resource 'mail'.
    Searching the domain for computer object 'mail'.
    Bind to domain controller \\GTMain.goldteam.co.uk.
    Check whether the computer object mail for node exists in the domain. Domain controller \\GTMain.goldteam.co.uk.
    Computer object for node exists in the domain.
    Verifying computer object 'mail' in the domain.
    Checking for account information for the computer object in the 'UserAccountControl' flag for CN=MAIL,CN=Computers,DC=goldteam,DC=co,DC=uk.
    Set password on mail.
    Configuring computer object 'mail in organizational unit CN=Computers,DC=goldteam,DC=co,DC=uk' as cluster name object.
    Get GUID of computer object with FQDN: CN=MAIL,CN=Computers,DC=goldteam,DC=co,DC=uk
    Provide permissions to protect object from accidental deletion.
    Write service principal name list to the computer object CN=MAIL,CN=Computers,DC=goldteam,DC=co,DC=uk.
    Set operating system and version in Active Directory Domain Services.
    Set supported encryption types in Active Directory Domain Services.
    Starting clustered role 'Cluster Group'.
    The initial cluster has been created - proceeding with additional configuration.
    Clustering all shared disks.
    Creating the physical disk resource for 'Cluster Disk 1'.
    Bringing the resource for 'Cluster Disk 1' online.
    Assigning the drive letters for 'Cluster Disk 1'.
    'Cluster Disk 1' has been successfully configured.
    Waiting for available storage to come online...
    All available storage has come online...
    Waiting for the core cluster group to come online.
    Configuring the quorum for the cluster.
    Configuring quorum resource to Cluster Disk 1.
    Configuring Node and Disk Majority quorum with 'Cluster Disk 1'.
    Moving 'Cluster Disk 1' to the core cluster group.
    Choosing the most appropriate storage volume...
    Attempting Node and Disk Majority quorum configuration with 'Cluster Disk 1'.
    Quorum settings have successfully been changed.
    The cluster was successfully created.
    Finishing cluster creation.

  • Problem in Adding JCheckBox Object to JTable

    I want to add a JCheckBox Object to A JTbale Coloumn but it shows the following message in JTable Coloumn-
    javax.swing.JCheckBox[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@f9f9d8,flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=2,bottom=2,right=2],paintBorder=false,paintFocus=true,pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=].
    Help Me in solving this problem

    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.

  • Help with adding rows to JTable

    Could any body help me with the following problem:
    I have created form where I use JTable.Initially I should show 5 rows in JTable. User can enter data into the cells.And commit I should store the data in database.
    My problem is how to dynamically add rows to JTable as user is entering the data. And how to retain the data in the cells when it is entered.
    Right now when user edits a cell and tabs to next one the data in previous cell disappears.
    Its Urgent can anybody help me
    Thanks in advance
    Babu

    The number of rows, number of columns, etc, are all determined by the TableModel used in the JTable.
    What is the easiest solution is to subclass AbstractTableModel adding methods to support your dynamic row adding/deleting/etc that you need. If you go to the javadoc for JTable, there's a link to a tutorial which contains most of what you need to know.
    - David

Maybe you are looking for