加上MouseListener,再editCell试试,方法名记不清了,你查查看
解决方案 »
- 一个表有多个主键,每一个主键都有外键关联,该如何建模?
- 有状态SESSION BEAN 和无状态SESSION BEAN 的区别和联系,大家怎么理解的.
- 利用PHPRPC协议,客户端访问服务端,查询数据库信息,求高手指点,小弟刚学习的菜鸟
- cascade在sqlserver2000种不起作用吗?
- J2EE如何入门
- struts如何清空actionform中的数据呢??
- 请问什么叫轻量级什么叫重量级?
- 请问各位:在实际的J2EE项目中,你们都用CMP的实体Bean,还是BMP型的?为什么?
- 关于ByteArrayInputStream 当数据流中有中文字符的时候,jdom处理xml会出错
- 200 分求助 ----- 乐思( wrox )"j2ee 编程指南1.3版" 随书源码
- 一个奇怪的问题,关于tomcat服务
- ie兼容问题!!!!
********************************************************************************
*
* Specifies the number of clicks needed to start editing.
********************************************************************************
* @param count an int specifying the number of clicks needed to start editing
* @see #getClickCountToStart
*/
public void setClickCountToStart(int count) {
clickCountToStart = count;
}
你只要实现new DefaultCellEditor(new JTextField()).setClickCountToStart(1)就行了,1就是click 1次。
下面是这个类的源代码
****************************************************************************************
/*
* @(#)DefaultCellEditor.java 1.38 00/02/02
*
* Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the proprietary information of Sun Microsystems, Inc.
* Use is subject to license terms.
*
*/package javax.swing;import java.awt.Component;
import java.awt.event.*;
import java.awt.AWTEvent;
import java.lang.Boolean;
import javax.swing.table.*;
import javax.swing.event.*;
import java.util.EventObject;
import javax.swing.tree.*;
import java.io.Serializable;/**
* The default editor for table and tree cells.
* <p>
* <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is appropriate
* for short term storage or RMI between applications running the same
* version of Swing. A future release of Swing will provide support for
* long term persistence.
*
* @version 1.38 02/02/00
* @author Alan Chung
* @author Philip Milne
*/public class DefaultCellEditor extends AbstractCellEditor
implements TableCellEditor, TreeCellEditor { //
// Instance Variables
// protected JComponent editorComponent;
protected EditorDelegate delegate;
protected int clickCountToStart = 1;//
// Constructors
// /**
* Constructs a DefaultCellEditor that uses a text field.
*
* @param x a JTextField object ...
*/
public DefaultCellEditor(final JTextField textField) {
editorComponent = textField;
this.clickCountToStart = 2;
delegate = new EditorDelegate() {
public void setValue(Object value) {
textField.setText((value != null) ? value.toString() : "");
} public Object getCellEditorValue() {
return textField.getText();
}
};
textField.addActionListener(delegate);
} /**
* Constructs a DefaultCellEditor object that uses a check box.
*
* @param x a JCheckBox object ...
*/
public DefaultCellEditor(final JCheckBox checkBox) {
editorComponent = checkBox;
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 new Boolean(checkBox.isSelected());
}
};
checkBox.addActionListener(delegate);
} /**
* Constructs a DefaultCellEditor object that uses a combo box.
*
* @param x a JComboBox object ...
*/
public DefaultCellEditor(final JComboBox comboBox) {
editorComponent = comboBox;
comboBox.putClientProperty("JComboBox.lightweightKeyboardNavigation", "Lightweight");
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;
}
};
comboBox.addActionListener(delegate);
} /**
* Returns the a reference to the editor component.
*
* @return the editor Component
*/
public Component getComponent() {
return editorComponent;
}//
// Modifying
// /**
* Specifies the number of clicks needed to start editing.
*
* @param count an int specifying the number of clicks needed to start editing
* @see #getClickCountToStart
*/
public void setClickCountToStart(int count) {
clickCountToStart = count;
} /**
* ClickCountToStart controls the number of clicks required to start
* editing.
*/
public int getClickCountToStart() {
return clickCountToStart;
}//
// Override the implementations of the superclass, forwarding all methods
// from the CellEditor interface to our delegate.
// public Object getCellEditorValue() {
return delegate.getCellEditorValue();
} public boolean isCellEditable(EventObject anEvent) {
return delegate.isCellEditable(anEvent);
}
public boolean shouldSelectCell(EventObject anEvent) {
return delegate.shouldSelectCell(anEvent);
} public boolean stopCellEditing() {
return delegate.stopCellEditing();
} public void cancelCellEditing() {
delegate.cancelCellEditing();
}//
// Implementing the TreeCellEditor Interface
// public Component getTreeCellEditorComponent(JTree tree, Object value,
boolean isSelected,
boolean expanded,
boolean leaf, int row) {
String stringValue = tree.convertValueToText(value, isSelected,
expanded, leaf, row, false); delegate.setValue(stringValue);
return editorComponent;
}//
// Implementing the CellEditor Interface
// public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected,
int row, int column) {
delegate.setValue(value);
return editorComponent;
}
//
// Protected EditorDelegate class
// protected class EditorDelegate implements ActionListener, ItemListener, Serializable { protected Object value; public Object getCellEditorValue() {
return value;
} public void setValue(Object value) {
this.value = value;
} public boolean isCellEditable(EventObject anEvent) {
if (anEvent instanceof MouseEvent) {
return ((MouseEvent)anEvent).getClickCount() >= clickCountToStart;
}
return true;
}
public boolean shouldSelectCell(EventObject anEvent) {
return true;
} public boolean startCellEditing(EventObject anEvent) {
return true;
} public boolean stopCellEditing() {
fireEditingStopped();
return true;
} public void cancelCellEditing() {
fireEditingCanceled();
} public void actionPerformed(ActionEvent e) {
DefaultCellEditor.this.stopCellEditing();
} public void itemStateChanged(ItemEvent e) {
DefaultCellEditor.this.stopCellEditing();
}
}} // End of class JCellEditor