如何在摆动GUI中使用BigDecimal? [英] How to use BigDecimal in swing GUIs?

查看:121
本文介绍了如何在摆动GUI中使用BigDecimal?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用BigDecimal表示Java SE应用程序中的产品价格.

I'm using BigDecimal to represent product prices in a Java SE application.

我应该使用哪种摆动组件,以允许用户输入仅两个小数位的数字并将其绑定到BigDecimal变量/对象的属性. (检查用户输入的内容)?

What swing component(s) should I use in order to allow the user to input numbers with only two decimal places and bound it to a BigDecimal variable/Object's property. (Checking that as the user types)?

我一直在玩JTextField,JFormattedTextField,NumberFormatter,MaskFormatter,但无法解决.

I've been playing with JTextField, JFormattedTextField, NumberFormatter, MaskFormatter but I can't work it out.

这些组件是否有任何组合和配置?还是应该扩展MaskFormatter,JTextField等...?

Is there any combination and configuration of those components to do that? or should I extend the MaskFormatter, the JTextField, ...?

推荐答案

我讨厌在东西上弄坏这些真正古老的线程,但是我的理解是StackOverflow每天都在哭泣,答案仍然无法解决.

I hate to necro these really old threads on stuff, but my understanding is StackOverflow cries inside every day an answer remains unsolved.

,因此您可以在此处签出代码: http://www. java2s.com/Code/Java/Swing-JFC/ABigDecimalobjectcustomformatter.htm

so you can checkout the code here: http://www.java2s.com/Code/Java/Swing-JFC/ABigDecimalobjectcustomformatter.htm

基本上设置为JFormattedTextField以使用DecimalFormat

basically set-up to a JFormattedTextField to use a DecimalFormat

这篇关于如何在摆动GUI中使用BigDecimal?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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