jformattedtextfield

Readonly JFormattedTextField

喜欢而已 提交于 2019-12-02 07:53:50
Supossing that a JFormattedTextField is enabled and contains a formatter, is there a way to make it readonly? With a JTextField , we just need to suply a custom Document and do all the control there, but with a JFormattedTextField I suppose that things are a little more complicated as we don't want to mess with its document filter. I really need this feature. So, is there a way to achieve this? UPDATE: Just my opinion, but it seems that the JFormattedTextField is so bad designed in this sense that it leaves no easy solution to this simple problem. Marcos You can simply use: JFormattedTextField

JTextField time in HH:mm:ss

心不动则不痛 提交于 2019-12-02 01:14:05
I have the estimated time the it would take for a particular task in minutes in a float. How can I put this in a JFormattedTextField in the format of HH:mm:ss ? no.good.at.coding JFormattedTextField accepts a Format object - you could thus pass a DateFormat that you get by calling DateFormat#getTimeInstance() . You might also use a SimpleDateFormat with HH:mm:ss as the format string. See also: http://download.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html#format If you're not restricted to using a JFormattedTextField , you might also consider doing your own formatting

NumberFormat parse not strict enough

时光总嘲笑我的痴心妄想 提交于 2019-12-01 16:10:48
I have a JFormattedTextField with a NumberFormat with Locale.US. So the decimal separator is the point and the grouping separator is the comma. Now I type the string "1,23" in this text field and move the focus to another component. I would expect the string to disappear (like it does when i type "a" instead of "1,23") because it is obviously not a valid representation of a number when using Locale.US. But instead the text in the text field is changed to "123". This is because the used NumberFormat is not strict when parsing and simply ignores the comma. Question : How can I tell NumberFormat

JFormattedTextField to format percent numbers?

放肆的年华 提交于 2019-12-01 08:46:58
问题 I would like to format a float number as a percent-value with JFormattedTextField that allows inputs from 0 to 100 percent (converted to 0.0f-1.0f), always shows the percent sign and disallows any invalid characters. Now I have experimented a bit with NumberFormat.getPercentInstance() and the NumberFormatter attributes but without success. Is there a way to create a JFormattedTextField that obeys to these rules with the standard classes? Or do I have to implement my own NumberFormatter? That

How to make JFormattedTextField accept integer without decimal point (comma)?

与世无争的帅哥 提交于 2019-12-01 08:39:24
I used JFormattedTextField with NumberFormat in this way: -Creat a JFormattedTextField refernce JFormattedTextField integerField; -Create a NumberFormat refernce NumberFormat integerFieldFormatter; -In the constructor: integerFieldFormatter = NumberFormat.getIntegerInstance(); integerFieldFormatter.setMaximumFractionDigits(0); integerField = new JFormattedTextField(integerFieldFormatter ); integerField.setColumns(5); .......... I meant to use it with integer numbers only, but when I type numbers like 1500 it is converted after losing focus to 1,500 , and exception thrown this is the first line

How to make JFormattedTextField accept integer without decimal point (comma)?

≯℡__Kan透↙ 提交于 2019-12-01 07:17:00
问题 I used JFormattedTextField with NumberFormat in this way: -Creat a JFormattedTextField refernce JFormattedTextField integerField; -Create a NumberFormat refernce NumberFormat integerFieldFormatter; -In the constructor: integerFieldFormatter = NumberFormat.getIntegerInstance(); integerFieldFormatter.setMaximumFractionDigits(0); integerField = new JFormattedTextField(integerFieldFormatter ); integerField.setColumns(5); .......... I meant to use it with integer numbers only, but when I type

Is there a way to put a colon in a jtextfield so it cant be removed?

此生再无相见时 提交于 2019-11-30 18:28:52
问题 I want a user to input time, so like 12:00, but I need to figure out a few things and I am wicked lost. Can I limit the text to 5 characters and how? Can I have a colon embedded in the code so that it cant be deleted by the user? Finally, can I take that code and verify that it is only the digits (ignoring the colon of course) 回答1: The answer is to use a JFormattedTextField and a MaskFormatter. For example: String mask = "##:##"; MaskFormatter timeFormatter = new MaskFormatter(mask);

How to set jFormattedTextField so it only allows 2 numbers?

醉酒当歌 提交于 2019-11-30 05:26:17
问题 I'm a beginner in Java, and NetBeans. I'm trying to make a simple program where you introduce 2 numbers and their sum gets divided by two. However, I'm using JFormattedTExtField s and I don't know how to customize the allowed input in them. Basically I'm trying to find out how to: Only allow numbers to be entered in JFormmatedTextField ; Only allow a certain amount of numbers; 回答1: You could use a NumberFormat and specify the maximum number of integer digits with setMaximumIntegerDigits. Here

JTextField stops using MaskFormatter after being cleared

纵饮孤独 提交于 2019-11-29 17:31:28
I'm doing a Sudoku solver and for that I want my JTextFields to only accept one of the numbers 123456789 as valid input. Therefore I use a MaskFormatter toghether with a JFormattedTextField. However when I clear all the TextFields by doing .setText("") the MaskFormatter doesn't work anymore. After clearing the textboxes I can write anything in them again. Why and how do I fix it? My code is basically: MaskFormatter formatter = new MaskFormatter("#"); formatter.setValidCharacters("123456789"); Font textFieldFont = new Font("Verdana", Font.BOLD, 30); for (int i = 0; i < 9; i++) { for (int j = 0;

JTextField stops using MaskFormatter after being cleared

↘锁芯ラ 提交于 2019-11-28 12:12:01
问题 I'm doing a Sudoku solver and for that I want my JTextFields to only accept one of the numbers 123456789 as valid input. Therefore I use a MaskFormatter toghether with a JFormattedTextField. However when I clear all the TextFields by doing .setText("") the MaskFormatter doesn't work anymore. After clearing the textboxes I can write anything in them again. Why and how do I fix it? My code is basically: MaskFormatter formatter = new MaskFormatter("#"); formatter.setValidCharacters("123456789");