jformattedtextfield

Limit characters in a JFormattedTextField

丶灬走出姿态 提交于 2020-01-17 04:57:05
问题 I'm trying to restrict the characters' number in a JFormattedTextField. I'm using a regular expression to validate the field but I need to limit the input too. I tried DocumentFilter and PlainDocument but it didn't work. Here is my code: public class UsingRegexFormatter { public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JFormattedTextField formattedField = new JFormattedTextField(new RegexFormatter("[0-9]+([,\\.][0-9]+)*"

jFormattedTextField's Formatter.setCommitsOnValidEdit(true) doesn't work at first focus

本小妞迷上赌 提交于 2020-01-09 03:53:05
问题 I have a jFormattedTextField and I set setCommitsOnValidEdit to true then I added an event listener to "property change" on "value" property. At first focus of that jFormattedTextField it doesn't call event listener method when typing in it. But on "focusLost" it calls event listener and after that when it receives focus again it calls event listener when typing. I want the event listener be called after any change in any time in that jFormattedTextField (Even in the fist focus). What's the

Applying a MaskFormatter to a column in my JTable, but the mask is only used on the first cell I edit in the column

為{幸葍}努か 提交于 2020-01-06 18:25:31
问题 ////DOB column formats to dd/mm/yy TableColumn dobColumn = table.getColumnModel().getColumn(3); DateFormat df = new SimpleDateFormat("dd/mm/yy"); JFormattedTextField tf = new JFormattedTextField(df); tf.setColumns(8); try { MaskFormatter dobMask = new MaskFormatter("##/##/##"); dobMask.setPlaceholderCharacter('0'); dobMask.install(tf); } catch (ParseException ex) { Logger.getLogger(DisplayStudents.class.getName()).log(Level.SEVERE, null, ex); } dobColumn.setCellEditor(new DefaultCellEditor(tf

How to make JDatePicker text field formatted for input?

∥☆過路亽.° 提交于 2020-01-04 09:38:28
问题 org.jdatepicker is used In my app input field should be editable, so I added datePicker = new JDatePickerImpl(datePanel, new DateLabelFormatter()); datePicker.setTextEditable(true); But now I can write any bs to it: screenshot. I need to add something like mf = new MaskFormatter("##.##.####"); mf .setPlaceholderCharacter('.'); to limit input to mask. But how to do this? JDatePickerImpl isn't a JFormattedTextField. When I choose date from calendar it's formatted right way. My

JTextField's real time formatting of user input

心不动则不痛 提交于 2019-12-25 02:52:02
问题 I would like to format the user input in real time, while they are typing. For example, if I want the user to enter a date, I would like the text field to show in light gray the date format. The user would only be able to enter valid digits while he is typing. If I need the user to enter a phone number, the format would be displayed in light gray in the text field and the user would only be able to enter valid digits... A javascript example of this can be found here: http://omarshammas.github

How to define a formatted text field in Swing so that the format restrictions are applied as you type?

家住魔仙堡 提交于 2019-12-24 17:12:05
问题 I need such a numeric text field on JFrame that restricts the input by a number with two digits after decimal point lays out the number separating every three digits i.e. 1 234 567,89. the number is displayed in correct format right away during typing I tried using JFormattedTextField: NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2); NumberFormatter numFormater = new NumberFormatter(nf); field1 = new javax.swing.JFormattedTextField(numFormater); However,

How to use JFormattedTextField allowing only letters and numbers

白昼怎懂夜的黑 提交于 2019-12-22 18:41:27
问题 I have this code and cannot get MaskFormatter right maskformatter MaskFormatter formatter = null; try { formatter = new MaskFormatter("HHHHHHH"); } catch (ParseException e) { e.printStackTrace(); } txtTroll = new JFormattedTextField(formatter); I need Any hex character (0-9, a-z or A-Z) and the "H" should give me only (0-9, a-z or A-Z) but im getting it wrong. When i type text only capital letters are typed and it's slow to and when i click away from the txtTroll all letters vanish 回答1: u can

Don't know how to fix my PropertyChangeListener on a JFormattedTextField

孤人 提交于 2019-12-22 11:27:54
问题 EDIT at end of post Test Code and Output import java.awt.EventQueue; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.text.NumberFormat; import javax.swing.JFormattedTextField; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.text.NumberFormatter; public class Test{ private JFormattedTextField input, input2; private NumberFormatter formatter; private PropertyChangeListener listener; public Test(){ formatter = new

Strict 24-hour time in JFormattedTextField

你离开我真会死。 提交于 2019-12-22 05:19:31
问题 I am trying to create a JFormattedTextField that only accepts a 24-hour time. I am very close to a solution, but have one case where the following code example does not work. If you enter the time "222" and change focus from the field, the time is corrected to "2202". I would like it to only accept a full 4 digit 24-hour time. This code works as I want in almost all cases, except the one I just mentioned. Any suggestions? public static void main(String[] args) throws ParseException {

Can you link values for two JFormattedTextFields?

别来无恙 提交于 2019-12-20 06:34:01
问题 I've got an interface with 2 JFormattedTextFields for which I need the values (not just the displayed text) to be identical. Ideally they should both be editable, with a change in one being mirrored in the other. I started by just sharing a single Document between the two, but quickly ran into the problem that this only links the displayed text, not the underlying value. (Silly me!) I haven't tried adding reciprocal PropertyChangeListeners for the "value" property because I would expect that