> I hope someone can help me... I'm editing a record of
> my table and I'm using a checkbox to indicate if my
> record is active or not. But when I edit it I don't
> know how to make my checkbox appears checked if my
> field is 1 or appears unchecked if it is 0...
If by a checkbox, you mean JCheckBox you have to call the setSelected() method on it with true or false depending on the value your field contains. If you meant HTML checkbox, you can use the javascript checked property on the checkbox.
Indeed. You'll have to sat more about the setting. I thought you were refering to a Swing JTable. In which case, the simplest way to go is to make sure your table model returns Boolean for the column class, then the JTable will automatically render the column with a check box. (And you should you booleans rather than 0 and 1!)
Demo:
import javax.swing.*;
import javax.swing.table.*;
public class TableExample {
public static void main(String[] args) {
Object[][] data = {
{"true", Boolean.TRUE},
{"false", Boolean.FALSE}
};
String[] columnNames = {"Strings", "Booleans"};
JTable table = new JTable(new MyModel(data, columnNames));
JFrame f = new JFrame("TableExample");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new JScrollPane(table));
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
class MyModel extends DefaultTableModel {
public MyModel(Object[][] data, Object[] columnNames) {
super(data, columnNames);
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
public Class<?> getColumnClass(int columnIndex) {
return (getRowCount() == 0) ? Object.class : getValueAt(0, columnIndex).getClass();
}
}
I still can't resolve my problem....
I have this:
Integer estatus = (Integer) EUsuarioDataProvider.getValue("tynEstatus");
if (estatus.intValue() == 1){
// setchecked my JCheckbox
chkActivo.setSelected(*);
}
* what I need to write as parameter in setSelected method?
> I hope this answer your question.... my application is for web using JSF
At last! The choice of technology is crucial to answering your problem. You should have mentioned JSF in the very first post. My JSF is rusty. I suggest you post your question to the JSF forum:
http://forum.java.sun.com/forum.jspa?forumID=427
And it goes without saying that there are no JCheckBoxs involved!
Thanx both DrLaszlo and Estudante
I write to this forum 'cause I'm really New in Java....
But right now I'm developing my first application with JSF in JCreator Studio. JosAH and myusername maybe could help me but they don't reply
I wrote my question in http://forum.java.sun.com/forum.jspa?forumID=881 but still nobody reply it.