Cloudgarden Discussion Board
This topic has 15 replies.
[ << Previous Topic | Start of Thread | >> Next Topic ]
Dynamic jtextfield population help
Author: Ted |
01/14/09 14:19 |
Reply |
Lets say I have a JPanel called JPanel1. It contains 17 jtextfields named
ISA01..ISA17
Now I have a array of 17 strings and I wish to populate the jtextfields
with the string values using something like:
for (x = 1;x<17;x++)
ISA0x.setText(array[x])
Is this possible? I need to be able to index the jtextfields so I can use
loops to populate them.
Thanks,
Ted |
|
Re: Dynamic jtextfield population help Author:Jonathan | Reply 1 of 15 | 01/15/09 05:39 | Reply | Hi Ted,
I'm afraid that kind of thing is outside the abilities of a GUI builder (at least, Jigloo doesn't handle it and I'd be surprised if any other GUI builder was able to do it). |
|
Re: Dynamic jtextfield population help Author:Ted | Reply 2 of 15 | 01/15/09 06:57 | Reply | Thanks for the quick reply but I have done this before many times in both VB and microsoft dev studio tho in one case, I had more control over the jtextfields and was able to store the jtextfields in an array that I could iterate through, the other way was the container held an index of the jtextfield objects.
I just think it is odd that there is no way to do this other than hardcoding all values
ISA01.setText(mytable.get(0)[0][0]);
ISA02.setText(mytable.get(0)[0][1]);
ISA03.setText(mytable.get(0)[0][2]);
ISA04.setText(mytable.get(0)[0][3]);
.
.
ISA17.setText(mytable.get(0)[0][17]);
this will be extremely...well, sloppy
maybe a way to do it with the container like (pseudo code here)
jpanel01.getobject(x).setText(array[x]);
|
|
Re: Dynamic jtextfield population help Author:Ted | Reply 3 of 15 | 01/15/09 07:10 | Reply | The other way I used to do this is:
JTextField jtf[]=new JTextField[10];
for(int i=0;i<9;i++)
{
jtf[i]=new JTextField();
}
but I do not know how to create this is jigloo |
|
Re: Dynamic jtextfield population help Author:Ted | Reply 4 of 15 | 01/15/09 13:08 | Reply |
Well I was able to add the above code and I get no errors but the
textfields do not display in the gui
I then added the line
private JTextField isa[];
up top and there is no error but a warning saying do I wish to add getters,etc
which doesn't seem to help
I then see I need to decipher what is going on here to get it to display?
.add(jPanel1Layout.createParallelGroup(GroupLayout.BASELINE)
.add(GroupLayout.BASELINE, ISA01, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
so would something like:
for (i=0;i<17;i++ {
.add(GroupLayout.BASELINE, isa[i], GroupLayout.PREFERRED_SIZE......
}
work?
|
|
Re: Dynamic jtextfield population help Author:Ted | Reply 5 of 15 | 01/15/09 13:32 | Reply | haha well that didn't work as it threw like 1000 errors, sorry about the posts btw, but I do not see an edit button.
Anyway, sum up, I am trying to find a way to group Jtextfields as an array
as in other IDE's. |
|
Re: Dynamic jtextfield population help Author:Ted | Reply 6 of 15 | 01/16/09 10:14 | Reply | Ok, I was just playing around with Vbasic 2005 which got
rid of control arrays which stinks but I was still able
to create a simple form with three textboxes named textbox1,textbox2, and textbox3 and update the text in them
with a loop when a button is clicked, is this possible in jigloo?
Dim i As Integer
For i = 1 To 3
Me.Controls.Item("TextBox" & i).Text() = "Test Loop No." & i
Next i
the big thing is how I can dynamically construct the variable name at runtime
with "Textbox" & i
The reason I am looking for a solution as I spent 21 weeks writing code with jigloo as my gui builder to find out I cannot do this but if it can't be done, it can't be done and I guess I will rewrite it in VB. |
|
Re: Dynamic jtextfield population help Author:Jonathan | Reply 7 of 15 | 01/21/09 18:09 | Reply | Hi Ted,
Thanks for the nudge - I have modified Jigloo to be able to handle the following kind of thing:
buttons = new JButton[3];
labels = new String[] {"one", "two", "three", "four"};
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new JButton();
buttons[i].setText(labels[i+1]);
this.add(buttons[i]);
}
It can successfully parse and display the above.
However, the editor will not be able to set, for instance, the text of buttons[2] to "five" - this would have to be done manually in the code. Does that seem reasonable to you? |
|
Re: Dynamic jtextfield population help Author:ted | Reply 8 of 15 | 01/21/09 19:26 | Reply | Holy Cow,
Now this is something I did not expect. I will test this out Thursday :)
I apologize as my frustration stemmed from ignorance in that maybe there was
a way to do this but perhaps I did just not know how.
If this works with jtextfields, which I imagine it will, this will be awesome
and as for the manual coding part, this is what I plan on doing for the most part so all is well :)
Regards,
Ted |
|
Re: Dynamic jtextfield population help Author:Jonathan | Reply 9 of 15 | 01/22/09 05:51 | Reply | OK, it's not been officially released yet, but if you download jigloo.jar from here:
http://cloudgarden1.com/jigloo/jigloo.jar
and replace the existing jigloo.jar in your eclipse's jigloo plugin folder then you should be able to try it out. Note, I'm still polishing it off, so it may not work perfectly and any comments you have would be useful. |
|
Re: Dynamic jtextfield population help Author:Ted | Reply 10 of 15 | 01/23/09 09:10 | Reply | | well, I tried to get the jar but I get "404 Error - Not Found" :( |
|
Re: Dynamic jtextfield population help Author:Ted | Reply 12 of 15 | 01/23/09 11:29 | Reply | | Well, I am unclear how to use this so I decided to do a quick test project. Created new java project, new gui/swing/jframe and opened up the gui editor to drag a textbox into the form so I could see where the code belongs and then edit it to resemble your example but it seems I am unable to drag any controls onto the form now ... I tried pasting your code into the initGUI routine and received no errors but the form does not display the buttons when the code is run though it runs with no errors. |
|
Re: Dynamic jtextfield population help Author:Jonathan | Reply 13 of 15 | 01/26/09 11:12 | Reply | Hi Ted,
Sorry for the delay - are you saying that new jar is broken (ie, it doesn't work as correctly as the old one did?) (if so, what is your eclipse version number? - I'm assuming you are using Jigloo 4.2.0 with the new jar file). |
|
Re: Dynamic jtextfield population help Author:Ted | Reply 14 of 15 | 01/26/09 18:11 | Reply | No problem on the delay. I have to double check tomorrow on the Eclipse version but it lists Jupiter's moon Ganymede during the splash screen on startup.
I wanted to leave my current code alone so I started a new blank project with the idea of dragging a textfield onto a new form/panel and then after seeing where and how the textfield was declared, altering it per your code snippet, to create an array of textfields but I can't drag any controls onto the form. They drag, but disappear and nothing happens when I release/unclick the textfield on the form.
But let me be as explicit as possible with what I am trying to attempt.
I have a form with a tabbed control, there are 5 tabs and I want to use x to index them so x = [0..4]
each tab has 4 groups so y = [0..3]
each group has 17 jtextfields so z = [0..16]
I delcare my array list:
ArrayList<String[][]> mytable = new ArrayList<String[][]>();
mytable.add(new String[5][17]);
I have a delimited flat file of 228 records which will load onto a form of 5 tabs, 4 groups each tab, 17 jtextboxes each group so the parser side of this code loads the arraylist:
for (x = 0 ; x < mytable.count() ; x++ //number of 2d arrays in arraylist
for (y = 0 ; y < 5 ; y++) //number of groups in tab
for (z = 0 ; z < sToken.length ; z++)
mytable.get(x)[y][z]=sToken[z]; // # jtextfields in group
The parser code can then pass the form loader all the data as an arraylist indexed by gui component number x,y,and z. I eventually intended to get rid of the arraylist and load directly to the form, but as I have never done java gui before I figured lets get the data parsed into an object with gui use in mind before learning how jigloo implements the gui.
This is why I ask for arrays of controls so I can map the index of the component tab#,group#,field# directly to the data index and just load the form with the same loop structure I used to load the arrayliist.
I ported my code to VB2005 only to my horror, discover they removed control arrays. Since the controls have no index property, and iterate in the order they were created, which is a variable I can't access:
dim myCntl as Control
for each cntl as Control in Me.group1
myCntrl = cntl
if mycntrl.cntrlType = textbox then 'there is a label per textbox
x = Me.textbox.name.split(0,1) ' |
|
Re: Dynamic jtextfield population help Author:Ted | Reply 15 of 15 | 01/26/09 18:30 | Reply | Damn, I forgot I can't edit my post to fix the indenting of my code segments which makes my post nearly illegible. Sorry, if the gist is lost, then what I wish ultimately is to drag a jtextfield onto a panel, copy/paste it into the panel and be asked, since copy was invoked, whether I am creating component array (yes or no)
if yes, then it creates an array (or list for that matter) of jtextfields adding textfields to the array as long as I continue pasting.
if no, follow current behavior. (which is what I would do with labels as they won't change so I don't care about them)
Then select everything in the panel and surround by a group container.
Select the group, copy/paste and get prompted whether I want to create an array of groups (yes no)
Once the tab has 4 groups, select the tab, rinse, repeat.
I hope this makes sense. |
|