如何在JTable中更改默认的停止编辑行为 [英] How to change default stop edit behavior in jtable

查看:85
本文介绍了如何在JTable中更改默认的停止编辑行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您在jtable中编辑单元格时,仅当焦点更改或输入一个命中值时,该值才会变为永久值(例如,如果将单元格值从"abc"更改为"xyz"并关闭窗口,丢失).当用户停止编辑时,如何使编辑永久化?

When you edit a cell in an jtable the value is made permanent only if the focus is changed or if one hits enter (for example if you change the cell value from "abc" to "xyz" and close the window the edit is lost). How do i make the edit permanent when the user stops editing?

我想我们必须更新单元格值,因为正在编辑单元格值,但是我不确定如何.感谢您的帮助!

I guess we have to update the cell value as the cell value is being editted but i am not sure how. Any help is appreciated!

提前谢谢!

推荐答案

我将在单元格上设置一个ActionListener,该单元将在每次击键后将单元格的值保存到变量中(假设单元格具有焦点).然后,无论窗口发生什么变化,此变量仍将包含单元格中当前包含的任何内容.很简单.

I would setup an ActionListener on the cell that saves the value of the cell to a variable after every keystroke (assuming the cell has focus). Then no matter what happens to the windows this variable will still contain whatever was currently in the cell. Pretty simple.

这篇关于如何在JTable中更改默认的停止编辑行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆