对于SWT 中的Spinner
控件,getText()
和getSelection()
有什么区别?我唯一能弄清楚的是返回类型。但是,我无法输入任何文本,只能输入数字。
getText(): Returns a string containing a copy of the contents of the receiver's text field, or an empty string if there are no contents.
getSelection(): Returns the selection, which is the receiver's position.
那么为什么我们有两种不同的 getter,我应该使用哪一种呢?
最佳答案
由于 Spinner
表示数字选择,您应该使用 getSelection()
,因为它会准确返回已选择的内容。
我不知道为什么 getText()
存在,但它会返回所选值的 String
表示形式,例如如果 getSelection()
返回 int
7
,getText()
将返回 String
“7”
。
关于java - SWT Spinner 的 getText() 和 getSelection() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43179149/