我正在创建一个 Swing GUI,我正在使用一系列 JTextField
。我希望能够向文本字段添加自定义属性。例如,这将用于在失去焦点时完成计算。
JTextField1.getCustomePram() * user input
我想要一个具有预定义值的文本字段,它用于乘以 20 英镑 * 5。因此默认参数将为 20,用户将输入数量,并在失去焦点时完成计算.
我正在使用 Netbeans 构建 GUI,我已经尝试扩展 JTextField
但老实说我不确定该怎么做,有任何建议或者如果我完全错误地解决这个问题请让我知道。
最佳答案
I want a text field that will have a predefined value, it is for multiplying £20 * 5. So the default param will be 20 and the user will put the qty in, and on loss of focus the calculation will be done. .. if I am going about this completely wrong please let me know.
你这样做是完全错误的。
为此,我可能会使用禁用的文本字段或单价标签(20 英镑),以及 JSpinner
对于数量 (5)。而不是计算焦点丢失,add a change listener并在数量发生变化时“实时”向用户显示所订购商品的新小计(和总计,如果相关)。
Need to look at how I need to implement ideas in Java.
一个不错的地方是 Visual Guide to Swing Components .将它们组合在复杂组件组的布局中。
关于java - 自定义组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10403640/