Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

checkbox check/uncheck controll  RSS feed

 
EMRE CANIAZ
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this code check/uncheck kontrol for checkboxes please wrote me better way (1) than this..

class CheckBoxHeader extends JCheckBox implements TableCellRenderer, MouseListener {
protected CheckBoxHeader rendererComponent;
private boolean mousePressed = false;

public CheckBoxHeader() {
rendererComponent = this;
}

public Component getTableCellRendererComponent(
JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
if (table != null) {
JTableHeader header = table.getTableHeader();
if (header != null) {
rendererComponent.setForeground(header.getForeground());
rendererComponent.setBackground(header.getBackground());
rendererComponent.setFont(header.getFont());
header.addMouseListener(rendererComponent);
}
}

setText("");
return rendererComponent;
}

protected void handleClickEvent(MouseEvent e) {
if (mousePressed) {
mousePressed = false;
doClick();----> (1)
checkAll();
}
}



public void mouseClicked(MouseEvent e) {
handleClickEvent(e);
((JTableHeader) e.getSource()).repaint();
}

private void checkAll() {
System.out.println("checkAll()");
boolean selected = rendererComponent.isSelected();
for (int row = 0; row < dbirsaliye.getRowCount(); row++) {
dbirsaliye.setValueAt(selected, row, cn_irsaliye._13_Check);
}
}

public void mousePressed(MouseEvent e) {
mousePressed = true;
}

public void mouseReleased(MouseEvent e) {
}

public void mouseEntered(MouseEvent e) {
}

public void mouseExited(MouseEvent e) {
}
}
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you contacted the author?

http://www.codeguru.com/java/articles/664.shtml
 
EMRE CANIAZ
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i am waiting answer from anyone
1.why we must use doClick()
2.i cant give any size to checkbox
[ April 25, 2008: Message edited by: EMRE CANIAZ ]
 
Brian Cole
Author
Ranch Hand
Posts: 947
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by EMRE CANIAZ:
yes i am waiting answer from anyone
1.why we must use doClick()
2.i cant give any size to checkbox


Unlike a typical cell renderer, this one maintains some state. This means
that this renderer can't be shared among multiple columns in a table (or
among multiple tables), but an individual instance is required for each
column.

With that in mind, I wouldn't say that we "must use" doClick(). It's just
a handy way to toggle the state of the renderer between the selected state
and the unselected state. Instead of doing doClick() we could instead do
something like selectedState = !selectedState, where selectedState is a boolean
field that we have added to the class. Then in getTableCellRendererComponent()
we would have to do rendererComponent.setSelected(selectedState).
(Perhaps this is what you are attempting to do with the mousePressed field?)

As for size, the table resizes the renderer for each cell before it paints it.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!