我从一个工作的jtable示例开始,我想添加一个事件侦听器,以便在值被更改时捕获。我发现最好的匹配是tablechanged()。我将它添加到self.table=jtable()并获取---typeerror:readonly属性。
我尝试了getfocus()并测试运行了代码,没有出现错误。如何使用tablechanged()?
"""
Swing JTable example in Jython.
Creates a simple table.
Greg Moore
Sept 2007
"""
from javax.swing import *
from java.awt import *
from javax.swing.table import DefaultTableModel
class Example:
def new_data(self.event): # I added this method ############
print "got to new data"
print event
def __init__(self):
frame = JFrame("Jython JTable Example")
frame.setSize(400, 150)
frame.setLayout(BorderLayout())
self.tableData = [
['numbers', '67890' ,'This'],
['mo numbers', '2598790', 'is'],
['got Math', '2598774', 'a'],
['got Numbers', '1234567', 'Column'],
['got pi','3.1415926', 'Apple'],
]
colNames = ('Col Labels','Go','Here')
dataModel = DefaultTableModel(self.tableData, colNames)
self.table = JTable(dataModel, tableChanged = self.new_data)
scrollPane = JScrollPane()
scrollPane.setPreferredSize(Dimension(300,100))
scrollPane.getViewport().setView((self.table))
panel = JPanel()
panel.add(scrollPane)
frame.add(panel, BorderLayout.CENTER)
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
frame.setVisible(True)
if __name__ == '__main__':
Example()
暂无答案!
目前还没有任何答案,快来回答吧!