, camickr, . MouseMotionListener JTable , , , . - , . , , , . -. , , , , , JToggleButton ( ). :
package guipkg;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class Grid extends JTable implements MouseListener {
int currentCellColumn = -1;
int currentCellRow = -1;
int previousCellColumn = -1;
int previousCellRow = -1;
public void detectCellAtCursor (MouseEvent e) {
Point hit = e.getPoint();
int hitColumn = columnAtPoint(hit);
int hitRow = rowAtPoint(hit);
if (currentCellRow != hitRow || currentCellColumn != hitColumn) {
this.editCellAt(hitRow, hitColumn);
currentCellRow = hitRow;
currentCellColumn = hitColumn;
}
}
}
package guipkg;
import javax.swing.table.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class TCEditor extends AbstractCellEditor implements TableCellEditor {
JToggleButton togglebutton = new JToggleButton();
public Component getTableCellEditorComponent (JTable Table, Object value, boolean isSelected, int rindex, int cindex) {
togglebutton.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent e) {
stopCellEditing();
}
});
if (value.toString().equals("true")) {
togglebutton.setSelected(true);
}
else {
togglebutton.setSelected(false);
}
togglebutton.setBorderPainted(false);
return togglebutton;
}
public Object getCellEditorValue () {
return togglebutton.isSelected();
}
}
, -