• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

checkbox check/uncheck controll

 
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) {
}
}
 
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 ]
 
Author
Posts: 974
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.
 
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic