Monday, 19 August 2013

JCheckBox does'nt trigger isselected

JCheckBox does'nt trigger isselected

I have a JPanel, which contains a JPanel and a JButtons. in the inner
JPanel I have some JCheckBoxes which are initially selected. I have added
an actionListener to my JButtons that check, if each of the JCheckBoxes
changed to unselected an action performs. but It doesn't work. this is my
code, where would the problem be?
public LimitPanel(String[] dates, int column) {
GridLayout layout = new GridLayout(1 + dates.length, 0);
setLayout(layout);
setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
setVisible(true);
this.dates = dates;
checks = new JCheckBox[dates.length][column];
for (int i = 0; i < dates.length; i++) {
for (int j = 0; j < column - 1; j++) {
checks[i][j] = new JCheckBox();
checks[i][j].setSelected(true);
checks[i][j]
.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
add(checks[i][j]);
}
}
}
in my Main Clas, I have another method that contains:
ResultSet e = connect.select("Invi", "*");
try {
while (e.next()) {
final int inviID = e.getInt("inviID");
JPanel pn = new JPanel();
pn.setSize(d.width, d.height);
pn.setLocation(0, 0);
pn.setLayout(new BoxLayout(pn, BoxLayout.PAGE_AXIS));
lp = new LimitPanel(st, 6);
pn.add(lp);
JButton sabt = new JButton(" ËÈÊ ");
sabt.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.out.println("saaaaaaaaaaaaaaaabt");
JCheckBox[][] jcb = new
JCheckBox[lp.getDates().length][5];
jcb = lp.getChecks();
for (int i = 0; i < lp.getDates().length; i++)
for (int j = 0; j < 5; j++) {
if (!jcb[i][j].isSelected()) {
System.out.println("naaaaaaaaa");
connect.insertLimit(inviID, (lp
.getDates())[i], j+"");
}
}
}
});
pn.add(sabt);
panels.add(pn);
}
} catch (SQLException e1) {
e1.printStackTrace();
}
setContentPane(panels.get(p));
revalidate();
I edited it to contain what ever is necessary, my problem is that
System.out.println("saaaaaaaaaaaaaaaabt"); is always works when I press
the button but what ever I do with the checkBoxes
System.out.println("naaaaaaaaa"); never works.

No comments:

Post a Comment