checkboxeditor.java

来自「mymp3的运行程序的源代码」· Java 代码 · 共 87 行

JAVA
87
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package mymp3.pp;import java.awt.Component;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.EventObject;import javax.swing.JCheckBox;import javax.swing.JTable;import javax.swing.event.CellEditorListener;import javax.swing.table.TableCellEditor;/** * * @author huliqing */public class CheckBoxEditor extends JCheckBox implements TableCellEditor{        public CheckBoxEditor() {        super();        addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                fireEditingStopped();            }        });    }    public Component getTableCellEditorComponent(JTable table,             Object value,             boolean isSelected,             int row, int column) {        setForeground(table.getSelectionForeground());        setBackground(table.getSelectionBackground());        setSelected((Boolean)value);        return this;    }    public Object getCellEditorValue() {        return this.isSelected();    }    public boolean isCellEditable(EventObject anEvent) {        return true;    }    public boolean shouldSelectCell(EventObject anEvent) {        return true;    }    public boolean stopCellEditing() {        fireEditingStopped();        return true;    }    public void cancelCellEditing() {        fireEditingStopped();    }    public void addCellEditorListener(CellEditorListener l) {        this.listenerList.add(CellEditorListener.class, l);    }    public void removeCellEditorListener(CellEditorListener l) {        this.listenerList.remove(CellEditorListener.class, l);    }        protected void fireEditingStopped() {        CellEditorListener list;        Object[] lists = listenerList.getListenerList();        for (int i = 0; i < lists.length; i++) {            if (lists[i] == CellEditorListener.class) {                list = (CellEditorListener) lists[i + 1];                list.editingStopped(changeEvent);            }        }    }        protected void fireEditingCanceled() {        fireEditingStopped();    }    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?