Sign in to follow this  
cwl157

[java] self writing java code

Recommended Posts

So i have a java GUI with a bunch of labels. I am using the netbeans gui creator to create it so i can not have an array of JLabels so i have to create them 1 at a time. I want to loop through them and set the text of each one seperately. If all the JLabel instances are jLabel1, jLabel2, jLabel3 etc, is there a way to have java create this instance name and call the setText() method for that instance. I thought about taking the word "jLabel" as a string and i can concatenate i from the loop to the end to product jLabel1, jLabel2, etc but then how do i make this string call the method of jLabel1 or jLabel2 or whatever it is. Is this possible? Thanks.

Share this post


Link to post
Share on other sites
ok so i have some questions like the

Object o = m.invoke(t, new Locale(args[1], args[2], args[3]));


it says the first parameter is the instance of the object that the method will be invoked from. And it declares t as a new instance of a class. However, i already have the instances i just want to invoke a method on each of them but the instance names increase by 1 each time, so can i pass in a string where t is, that string being "jLabel1" and then have it take it as an instance of JLabel named jLabel1? I am confused about how i apply this to what i want cause this is about getting methods from a class and creating new instances.

Share this post


Link to post
Share on other sites
Quote:
Original post by cwl157
So i have a java GUI with a bunch of labels. I am using the netbeans gui creator to create it so i can not have an array of JLabels so i have to create them 1 at a time.

That's why I prefer doing my GUIs in code. It's really not that hard and it gives you so much more control...

Share this post


Link to post
Share on other sites
no its impossible for me to do that. Maybe now that i have used the GUI builder a little i could understand it more, but i tried all that once and spent about 2 days lost in all the container classes and what not.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this