The general setup i have is a JComboBox with a list of options. When one is chosen four Jbuttons appear with labels depending on what was selected in the JComboBox.
When you click one of those buttons it reads out from an array (which contains the option in the JComboBox) into a set of JTextFields.
I am looking to have it read out and skip the option that was chosen in the JComboBox.e.g. if you choose "Three" in the JComboBox and the array contains "One" "Two" "Three" "Four" it will read out "One" into the first box, "Two" into the second box and "Four" into the third box.
I have made a counter that will skip the option in the JComboBox
Where list is my array, comboChoice is the option chosen from the JComboBox and gui.matches are the JTextFields it reads out to.
My problem is it reads "One" in the first box, "Two" in the second box, the third box is blank and reads "Four" in the fourth box.
I have tried making a parallel counter.e.g. something like
so that the counter for the array and the counter for the read out are seperate, and that the counter for the read out steps back (and therefore steps back a box) on coming to the option chosen in the JComboBox.
What seems to happen though is that you get a readout in all boxes but they all end up being the last element of the array.
Does anyone have any advice on how best to achieve what i am looking to do?
So you'll have 4 JTextFields filled with 3 items. What's supposed to be in the 4th JTextField?
From what you've told us (my interpretation, anyway):
1. each of the 4 JTextFields can contain either "One", "Two", "Three", or "Four";
2. apparently none of the JTextFields will repeat what is shown in any of the other JTextFields
3. "One", "Two", "Three", and "Four" are displayed in order (with one item missing)
4. The item shown in the JComboBox is not shown (or skipped) in the JTextFields
The index of the chosen item in JComboBox can be obtained using the getSelectedIndex() method.
Using a switch or if/else logic, that index could then be used to determine which item WILL NOT appear (will be skipped) in the JTextFields, remembering that index 0 will correspond to "One", index 1 to "Two", etc.
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Joined: May 17, 2012
Thanks for the reply Greg.
I have sorted it now as of the code below, but to clarify a little, the forth JTextField is left blank and will be set invisible, or to be more precise all JTextFields will be set invisible to start with and only set visible when they have data entered into them as i will be using multiple arrays of varying lengths so not all JTextFields will be needed at all times.
I see someone edited my post so that the code was separated, how do i do that so i can make it clearer in future?
wayne morton wrote:I have sorted it now as of the code below...
Please UseCodeTags (←click) when you post code. I suspect somebody cleaned up your previous post, but I'll leave you to do it this time. Just read the page (thoroughly) and use the 'Edit' button to add them to your post. You'll be amazed how much better it looks.
Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here