package dao;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
public class MyTableCellEditor extends JRadioButton implements TableCellEditor {
protected EventListenerList listenerList = new EventListenerList();
protected ChangeEvent changeEvent = new ChangeEvent( this);
public MyTableCellEditor() {
super();
addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
fireEditingStopped();
}
});
}
public void addCellEditorListener(CellEditorListener listener) {
listenerList.add(CellEditorListener. class, listener);
}
public void removeCellEditorListener(CellEditorListener listener) {
listenerList.remove(CellEditorListener. class, listener);
}
protected void fireEditingStopped() {
CellEditorListener listener;
Object[] listeners = listenerList.getListenerList();
for ( int i = 0; i < listeners.length; i++) {
if (listeners[i] == CellEditorListener. class) {
listener = (CellEditorListener) listeners[i + 1];
listener.editingStopped(changeEvent);
}
}
}
protected void fireEditingCanceled() {
CellEditorListener listener;
Object[] listeners = listenerList.getListenerList();
for ( int i = 0; i < listeners.length; i++) {
if (listeners[i] == CellEditorListener. class) {
listener = (CellEditorListener) listeners[i + 1];
listener.editingCanceled(changeEvent);
}
}
}
public void cancelCellEditing() {
fireEditingCanceled();
}
public boolean stopCellEditing() {
fireEditingStopped();
return true;
}
public boolean isCellEditable(EventObject event) {
return true;
}
public boolean shouldSelectCell(EventObject event) {
return true;
}
public Object getCellEditorValue() {
return new Boolean( this.isSelected());
}
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) {
return this;
}
public void AddRadioButton(JTable jtable)
{
TableCellEditor myRenderer = new MyTableCellEditor();
jtable.getColumnModel().getColumn(0).setCellEditor(myRenderer);
jtable.getColumnModel().getColumn(0).setHeaderValue( "选择");
}
}
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
public class MyTableCellEditor extends JRadioButton implements TableCellEditor {
protected EventListenerList listenerList = new EventListenerList();
protected ChangeEvent changeEvent = new ChangeEvent( this);
public MyTableCellEditor() {
super();
addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
fireEditingStopped();
}
});
}
public void addCellEditorListener(CellEditorListener listener) {
listenerList.add(CellEditorListener. class, listener);
}
public void removeCellEditorListener(CellEditorListener listener) {
listenerList.remove(CellEditorListener. class, listener);
}
protected void fireEditingStopped() {
CellEditorListener listener;
Object[] listeners = listenerList.getListenerList();
for ( int i = 0; i < listeners.length; i++) {
if (listeners[i] == CellEditorListener. class) {
listener = (CellEditorListener) listeners[i + 1];
listener.editingStopped(changeEvent);
}
}
}
protected void fireEditingCanceled() {
CellEditorListener listener;
Object[] listeners = listenerList.getListenerList();
for ( int i = 0; i < listeners.length; i++) {
if (listeners[i] == CellEditorListener. class) {
listener = (CellEditorListener) listeners[i + 1];
listener.editingCanceled(changeEvent);
}
}
}
public void cancelCellEditing() {
fireEditingCanceled();
}
public boolean stopCellEditing() {
fireEditingStopped();
return true;
}
public boolean isCellEditable(EventObject event) {
return true;
}
public boolean shouldSelectCell(EventObject event) {
return true;
}
public Object getCellEditorValue() {
return new Boolean( this.isSelected());
}
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) {
return this;
}
public void AddRadioButton(JTable jtable)
{
TableCellEditor myRenderer = new MyTableCellEditor();
jtable.getColumnModel().getColumn(0).setCellEditor(myRenderer);
jtable.getColumnModel().getColumn(0).setHeaderValue( "选择");
}
}
package dao;
import java.awt.Component;
import javax.swing.JRadioButton;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
public class MyTableCellRenderer implements TableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) { // 根据特定的单元格设置不同的Renderer,假如你要在第2行第3列显示图标
JRadioButton jbtn= new JRadioButton();
return jbtn;
}
public void AddJRadioButton(JTable jtable)
{
TableCellRenderer myRenderer = new MyTableCellRenderer();
jtable.getColumnModel().getColumn(0).setCellRenderer(myRenderer);
jtable.getColumnModel().getColumn(0).setHeaderValue( "选择");
}
}
import java.awt.Component;
import javax.swing.JRadioButton;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
public class MyTableCellRenderer implements TableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) { // 根据特定的单元格设置不同的Renderer,假如你要在第2行第3列显示图标
JRadioButton jbtn= new JRadioButton();
return jbtn;
}
public void AddJRadioButton(JTable jtable)
{
TableCellRenderer myRenderer = new MyTableCellRenderer();
jtable.getColumnModel().getColumn(0).setCellRenderer(myRenderer);
jtable.getColumnModel().getColumn(0).setHeaderValue( "选择");
}
}
转载于:https://blog.51cto.com/leelei/308277