Forums Register Login

Swing validation

+Pie Number of slices to send: Send
I finished this program and when I tested the first code group at the bottom validating the combobox entries it worked fine. Now this program freezes when I touch the radio buttons or comboboxes. The last block of code is supposed to immediatley revert back to the first selection in the array when the same position is picked in another combobox. I have looked it over and have no idea why it just freezes. The problem has to be in the lat bit performing the validation because it was fine before.

+Pie Number of slices to send: Send
In your action listener you are changing a combo box, which causes the action listener to be called, which then changes a combo box, which causes the action listener to be called, which then changes... you get the picture I hope.

It's a pity you wrote 500 lines of code before testing anything; try not to do that in future.
+Pie Number of slices to send: Send
MMM okay. Well I've figured out that it only breaks around the fifth box check but not sure why it's affecting the radio buttons and why it works until that point. Also refer to earlier post, I had checked the first block and just like now it did work, it just does not work all teh way through.
+Pie Number of slices to send: Send
I tried your code and it hung on the first radio button click.

Your post sounds like you tying yourself in knots. I suspect you are going to have to delete a lot of that code (> 95%) and see what happens.
I do not like the multiple ifs. You are throwing an inappropriate Exception because none of those Strings is null. You should not be catching unchecked Exceptions. You need to alter your design and to check the contents of the fields when you push any of the buttons.
You should also not make a display class implement action listener. Apply different listeners to the different components. Or implement a Component, maybe a menu item, maybe a button, which checks that the fields contain text and then compiles the team.

Can you add some sort of listener to the combo boxes which removes the selected position from all the other boxes?
+Pie Number of slices to send: Send
I would suggest you would have a lot less code if you used an array rather than nine variables. And also, don't call setSelectedIndex(0) if index 0 is already selected -- that may be causing the infinite loop.

You should also avoid using == to compare String values, although you are somehow getting away with it here. Use the equals() method instead.

+Pie Number of slices to send: Send
 

Paul Clapham wrote:. . . avoid using == to compare String values, although you are somehow getting away with it here. . . .

A long time ago when I was working for the MSc, we had one chap on the course who had written a lot of C#, where (I think) == is overloaded on Strings. So he used == throughout and it worked nicely, because all the Strings were literals which were automatically interned, or assigned from those literals. “It works all right until I serialise it, Campbell, but it won't work afterwards.”

Even at that tender age I realised there was a problem because the deserialised Strings were being compared to the original literals with == and that wouldn't work; they were now new objects. Changing every occurrence of == to equals sorted out the problem.
Whatever you say buddy! And I believe this tiny ad too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 511 times.
Similar Threads
ComboBox GUI
GridBagLayout...!
problem in textfield width...
JTextField size changes with JLabel text length
arrange the spacing between components
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:01:05.