Java Swing Help - Please!

Java Swing Help - Please!

Author
Discussion

roadsweeper

Original Poster:

3,787 posts

280 months

Thursday 5th September 2002
quotequote all
I'm trying to use a JFormattedTextField and InputVerifier to check that a user has entered a valid value. The validation works perfectly and I have written a custom event that is fired by the InputVerifier when the validation fails, the intention being that a dialog is displayed with the appropriate error message.
My problem is that if I tab away from the field everything works perfectly, however, if I use the mouse to click on another field then the InputVerifier is called twice, causing the event to be fired twice, and hence the dialog to be displayed twice. Obviously this is unaccaeptable - anyone have any idea how to fix this as it's driving me mad. It should be so simple!!


For info, here's the code snippet:

// Set up the InputVerifier.
m_textFieldVerifier = new NumberTextFieldInputVerifier();
m_textFieldVerifier.setAllowPositiveAndNegative(NumberTextFieldInputVerifier.POSITIVE);
m_textFieldVerifier.setMaximumValueAllowed(new Double(100));
m_textFieldVerifier.addValidationFailListener(this);

// Define a NumberFormat to restrict acceptable inputs.
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(2);
Double saPercentage = m_saClientPercentage.getAllocation();

//Create the JFormattedTextField.
JFormattedTextField textField = new JFormattedTextField(nf);
textField.setInputVerifier(m_textFieldVerifier);
textField.setHorizontalAlignment(JTextField.CENTER);
textField.setValue(saPercentage);
setTextFieldSize(textField);
panel.add(textField);

roadsweeper

Original Poster:

3,787 posts

280 months

Thursday 5th September 2002
quotequote all
Come on, there must be someone on here who can help!?

RichB

52,648 posts

290 months

Thursday 5th September 2002
quotequote all
Probably the wrong forum mate! (just a guess ) Have you tried looking for a Java chat group? There are some out there... Rich.

Size Nine Elm

5,167 posts

290 months

Thursday 5th September 2002
quotequote all
Just thinking off the top of my head - can you configure whcih events the text field fires off the verifier on? Guess you're getting a focus event and a click event, or summat like that...

roadsweeper

Original Poster:

3,787 posts

280 months

Thursday 5th September 2002
quotequote all
Thanks for trying to help but I've cracked it now thank God!

As regards an appropriate forum, fair point, but as a regular I know there are loads of IT geeks on here (me included) so there was a reasonable chance someone might know! (Just see the 'Anonymous girls on my phone thread' for definitive proof! )