craftleft.gif (3002 bytes)QuickTable
Home | API | Tutorial | Download | Support | Contact topblack.gif (108 bytes)


QuickTable User Cp  |  Register  |  Members  |  Search  |  Help
    |- QuickTable Discussion Forums > Column Post New Topic   Post A Reply
How can I programmatically change checkbox settings??? printer friendly version
next newest post | next oldest post
Author Messages
callagga
Unregistered
Edit or delete this message Reply w/Quote
Posted Sunday, March 27, 2005 @ 17:33:06  

Hi,

Could anyone advise how to programmatically select or deselect a checkbox? (e.g. I have a routine to optimally select items)

Background - I am using DBTable with checkbox's in a Java application (non-database) using the below-mentioned suggested approach from the quicktable advanced tutorial.

c = dBTable1.getColumn(4);
c.setPreferredWidth(60);
h = new Hashtable();
h.put("Y", new Boolean(true));
h.put("N", new Boolean(false));
dBTable1.setCellComponent(c,Column.CHECKBOX_CELL,h);

Thanks in advance
Greg

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Sunday, March 27, 2005 @ 20:38:31  

To programmatically select or deselect a checkbox assign the checkbox true/false data to that cell.

In your case, you are using
h.put("Y", new Boolean(true));
h.put("N", new Boolean(false));

so,
Y is checked
N is unchecked.

so e.g dbTable.setValueAt("Y", 1,2) will select checkbox , dbTable.setValueAt("N", 1,2) will deselect.

callagga
Private

Gender: Unspecified
Location:
Registered: Mar 2005
Status: Offline
Posts: 5

Click here to see the profile for callagga Send email to callagga Send private message to callagga Find more posts by callagga Edit or delete this message Reply w/Quote
Posted Sunday, March 27, 2005 @ 22:10:24  

Many thanks for the quick replay,

The penny has dropped. :)

Out of curiosity, is the "setValueAt" functionality and the use of "setCellModel" something you have build into DBTable itself? I'm guess this as I can't quite see the same functionality in the java base classes (e.g. JComponent, etc). I guess I went looking to try to establish whether I shoudl have been able to answer this question for myself if I had of had more knowledge of the SWING/AWT classes.

Thanks again
Greg

callagga
Private

Gender: Unspecified
Location:
Registered: Mar 2005
Status: Offline
Posts: 5

Click here to see the profile for callagga Send email to callagga Send private message to callagga Find more posts by callagga Edit or delete this message Reply w/Quote
Posted Sunday, March 27, 2005 @ 22:17:27  

PSS.

If I wanted to also perform specific code every time a user clicks on a checkbox, I'm guessing the recommended approach is via the following concept (from the advanced help)? That is, you then have to check to see if it was a change in the column you were interested? That is, there's no specific way of attaching a special listener to the CHECKBOX column?

class MyCellListener implements DBTableCellListener
{
public Object cellValueChanged(int row, int col, Object oldValue, Object newValue)
{
if( col == 3)

Thanks
Greg

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Monday, March 28, 2005 @ 21:39:07  

setValueAt method is similar to setText() or setValue() in other components. Since this is a table, in addtion to the value, you also need the row column, that is why it is setvalueat.

setCellComponent is a method specific to quicktable to simply the process of setting cell editors/renderers.

JTables reuses one single checkbox for all cells in a column. so if you attached a listener, you may not get the right value, so it is not a good idea to attach listener to checkbox. You need to use the DBTableCellListener as you have mentioned above.

callagga
Private

Gender: Unspecified
Location:
Registered: Mar 2005
Status: Offline
Posts: 5

Click here to see the profile for callagga Send email to callagga Send private message to callagga Find more posts by callagga Edit or delete this message Reply w/Quote
Posted Saturday, April 9, 2005 @ 16:24:32  

Thanks (have been out of town in recent weeks)

I've noted however that within my DBTableCellListener, using cellValueChanged, that the ROW number returned is OK until I sort the table on one of the columns. Then the row number being returned doesn't reflect the new resorting of the application.

The problem if one wants to use the ROW number retuned (in DBTableCellListener) to retrieve the row data from the model (e.g. myDbTable.getRowObject(row)) you get the wrong row object. This seems to be because the former is based on the table structure prior to the sort, whereas the later is based on the latest post-sort.

Any suggestions in terms of how to work around this.

In other words I want to get the row object for the row for which a cell value was changed, but I want this to work even after the user has clicked on the column headings to sort the table.

Thanks
Greg

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Sunday, April 10, 2005 @ 23:16:33  

Please download the latest version 2.0.5.20, this problem is resolved
callagga
Private

Gender: Unspecified
Location:
Registered: Mar 2005
Status: Offline
Posts: 5

Click here to see the profile for callagga Send email to callagga Send private message to callagga Find more posts by callagga Edit or delete this message Reply w/Quote
Posted Monday, April 11, 2005 @ 07:38:25  

Hi,

I've downloaded that latest version but noted a new a potential introduced issue.

I load the table (which has the first column a checkbox column, per my previous post in this thread), but when I go to determine which rows are selected, I note that via the "_dbTable.getValueAt(i, COLUMN_SELECTED)" method that if the 1st checkbox column hasn't previously be selected the value is that of the 2nd column. That is, if you look at the full table via a dbTable.getDataVector() in debug mode of your IDE you can see that for those columns where the row hadn't been selected the column number are out of alignment.

For example: (conceptual extract via dbTable.getDataVector())
item1: [0]="Y",[1]=123,[2]="Description xsdf"
item2: [0]="N",[1]=123,[2]="Description xsdf"
item3: [0]=123,[1]="Description xsdf" <==THIS ROW HADN'T BEEN SELECTED PREVIOUSLY

Do you think this is an introduced bug?

Cheers
Greg

callagga
Private

Gender: Unspecified
Location:
Registered: Mar 2005
Status: Offline
Posts: 5

Click here to see the profile for callagga Send email to callagga Send private message to callagga Find more posts by callagga Edit or delete this message Reply w/Quote
Posted Monday, April 11, 2005 @ 19:14:57  

PS. With the latest version I also noted that I'm getting additional columns being displayed above and beyond the ones I specifiy in my "String[] COLUMN_HEADINGS", which I use in "_dbtable.refreshDataObject(_fileList, COLUMN_HEADINGS)".

It seems that the table is now displaying a column for all the getters in my collection I used to populate the table (i.e. _fileList passed to the table via refreshDataObject). In fact there is a column for the "toString" method that is present in my _fileList (which is a collection of custom objects).

Cheers
Greg

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Tuesday, April 12, 2005 @ 01:26:49  

myDbTable.getRowObject(row) and column heading issues were resolved. Please download the latest version.

I am not able to reproduce the column alignment problem. Please send a small sample code reproducing this problem , we will look into it.

Post New Topic   Post A Reply Jump to:
Contact Us | QuickTable - A Java DBGrid | Privacy Policy All times are GMT -5 Hours.
Welcome to QuickTable Forums, Guest!  
Login
Username :
Password :
In order to fully utilize the abilities of this board, you are required to register as a member. Registration is free, and allows you to do lots of things including turning on or off certain features of this board. Register now!
Powered by CuteCast v2.0 BETA 2
Copyright © 2001-2003 ArtsCore Studios