资源简介
这个demo里面实现的功能有对比表格进行渲染,在单元格中添加控件等功能
代码片段和文件信息
package JTableDemo;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.io.Serializable;
import java.util.Eventobject;
import javax.swing.AbstractCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.table.TableCellEditor;
public class MyTableCellEditor extends AbstractCellEditor implements TableCellEditor{
protected JComponent editorComponent;
protected EditorDelegate delegate;
protected int clickCountToStart = 1;
public MyTableCellEditor(final JTextField textField) {
editorComponent = textField;
this.clickCountToStart = 2;
delegate = new EditorDelegate() {
public void setValue(object value) {
textField.setText((value != null) ? value.toString().trim() : ““);
}
public object getCellEditorValue() {
return textField.getText();
}
};
textField.addActionListener(delegate);
}
public MyTableCellEditor(final JCheckBox checkBox) {
editorComponent = checkBox;
checkBox.setSelected(false);
checkBox.setHorizontalAlignment(JCheckBox.CENTER);
delegate = new EditorDelegate() {
public void setValue(object value) {
boolean selected = false;
if (value instanceof Boolean) {
selected = ((Boolean)value).booleanValue();
}
else if (value instanceof String) {
selected = value.equals(“true“);
}
checkBox.setSelected(selected);
}
public object getCellEditorValue() {
return Boolean.valueOf(checkBox.isSelected());
}
};
checkBox.addActionListener(delegate);
checkBox.setRequestFocusEnabled(false);
}
public MyTableCellEditor(final JComboBox comboBox) {
editorComponent = comboBox;
comboBox.putClientProperty(“JComboBox.isTableCellEditor“ Boolean.TRUE);
delegate = new EditorDelegate() {
public void setValue(object value) {
comboBox.setSelectedItem(value);
}
public object getCellEditorValue() {
return comboBox.getSelectedItem();
}
public boolean shouldSelectCell(Eventobject anEvent) {
if (anEvent instanceof MouseEvent) {
MouseEvent e = (MouseEvent)anEvent;
return e.getID() != MouseEvent.MOUSE_DRAGGED;
}
return true;
}
public boolean stopCellEditing() {
if (comboBox.isEditable()) {
// Commit edited value.
comboBox.actionPerformed(new ActionEvent(
MyTableCellEditor.this 0 ““));
}
return super.stopCellEditing();
}
};
comboBox.addActionListener(delegate);
}
public Component getComponent() {
return editorComponent;
}
public void setClickCountToStart(int count) {
clickCountToStart = count;
}
public int getClickCountToStart() {
return clickCountToStart;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 301 2018-06-11 14:34 SwingTest\.classpath
文件 385 2018-06-11 14:34 SwingTest\.project
目录 0 2018-06-11 16:51 SwingTest\.settings\
文件 629 2018-06-11 14:34 SwingTest\.settings\org.eclipse.jdt.core.prefs
目录 0 2018-06-11 16:51 SwingTest\bin\
目录 0 2018-06-11 16:51 SwingTest\bin\JTableDemo\
文件 1224 2018-06-11 16:47 SwingTest\bin\JTableDemo\MyTableCellEditor$1.class
文件 1343 2018-06-11 16:47 SwingTest\bin\JTableDemo\MyTableCellEditor$2.class
文件 1687 2018-06-11 16:47 SwingTest\bin\JTableDemo\MyTableCellEditor$3.class
文件 1915 2018-06-11 16:47 SwingTest\bin\JTableDemo\MyTableCellEditor$EditorDelegate.class
文件 3917 2018-06-11 16:47 SwingTest\bin\JTableDemo\MyTableCellEditor.class
文件 1032 2018-06-11 15:50 SwingTest\bin\JTableDemo\MyTableModel.class
文件 1783 2018-06-11 16:42 SwingTest\bin\JTableDemo\MyTableReander.class
文件 727 2018-06-11 16:41 SwingTest\bin\JTableDemo\TableTest$1.class
文件 2699 2018-06-11 16:41 SwingTest\bin\JTableDemo\TableTest.class
目录 0 2018-06-11 16:51 SwingTest\src\
目录 0 2018-06-11 16:51 SwingTest\src\JTableDemo\
文件 5084 2018-06-11 16:47 SwingTest\src\JTableDemo\MyTableCellEditor.java
文件 763 2018-06-11 15:50 SwingTest\src\JTableDemo\MyTableModel.java
文件 1639 2018-06-11 16:42 SwingTest\src\JTableDemo\MyTableReander.java
文件 1956 2018-06-11 16:41 SwingTest\src\JTableDemo\TableTest.java
- 上一篇:最小二乘支持向量机
- 下一篇:基于创惟GL3520的一拖四USB3.0拓展原理图
评论
共有 条评论