firsco bear

Greenhorn
+ Follow
since Feb 07, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by firsco bear

Thanks guys.

May be i am getting confused.

i am stuck at this point.
- Trying to select mulitple checkboxes at a time.
Can anyone please help me how can i select multiple checkboxes at atime.
19 years ago
Here is my code i am using to add a checkbox column onto JTable

My CellEditor class
........................



public class CheckBoxCellEditor extends AbstractCellEditor implements TableCellEditor {

protected JCheckBox checkBox;;

public CheckBoxCellEditor() {
checkBox = new JCheckBox();
checkBox.setHorizontalAlignment(SwingConstants.CENTER);
checkBox.setBackground( Color.white);

}

public Component getTableCellEditorComponent(
JTable table,
Object value,
boolean isSelected,
int row,
int column) {

if(column==0)
{
checkBox.setSelected(((Boolean) value).booleanValue());

Component c =table.getDefaultRenderer(String.class).getTableCellRendererComponent(table, value, isSelected, false, row, column);

if (c != null) {
//checkBox.setBackground(c.getBackground());
}
}


return checkBox;

}


public Object getCellEditorValue() {
return new Boolean(checkBox.isSelected());



}





}





In my Tablemodel I implemented these two methods.
public Class getColumnClass(int col)
{ switch (col)
{
case 0: return Boolean.class;
default: return Object.class;
}
}





public boolean isCellEditable(int rowIndex, int columnIndex) {

if(columnIndex == 0){
return true;}
else {return false; }
}




In my class I am setting the column with renderer and editor like this


TableColumn tc = GlobalAccess.tblChanges.getColumnModel().getColumn(0);
tc.setCellEditor(new CheckBoxCellEditor());
tc.setCellRenderer(GlobalAccess.tblChanges.getDefaultRenderer(Boolean.class));

SO AS OF NOW I AM ABLE TO SHOW THE CHECKBOX ON THE JTABLE FIRST COLUMN.
NOW I WANT TO ADD FUNTIONALITY SO THAT WHEN I SELECT CHECKBOXES(MULITPLE), I WANT TO SELECT THE CORRESPONDING ROWS.
BUT NOW WHEN I CLICK ON CHECKBOX, IT IS GETTING SELECTED, BUT WHEN I CILCK ON SECOND THE FIRST CHECKED CHECKBOX IS AGAIN GETTING DESELETED.

CAN ANYONE PLEASE HELP ME WHAT I AM MISSING.
19 years ago
Hi,
I an new to swing .so please bear with me

I am trying to implement functionality something similar to yahoo mail.
I have a JTable having 5 columns. now i want to add one more column which has checkbox for each row.
Then when the user selects multiple checkboxs and clicks on add, i want to select corresponding rows from the table and add in the db.

Till now i am able to add a column to the table, showing checkbox in each row.

now my problem is i am not able to select multiple checkboxes at a time.when i select the second one, firstone is getting deselected.
can anyone please tell me what should i do to select multiple checkboxes (select multiple rows).
I tried for examples in net..but no help.
can anyone please give me a sample example, if they have...
19 years ago