Results 1 to 7 of 7
- 08-12-2010, 01:22 PM #1
Member
- Join Date
- Aug 2010
- Location
- England
- Posts
- 12
- Rep Power
- 0
SOLVED: Changing different Swing control and their properties dynamically?
So hypothetically, say I have two jTextPanes: tp1 and tp2, and an integer i.
I want a certain piece of text to be printed in either tp1 or tp2 depending on the integer I by putting "tp" + i into a string and using that to search for the swing control. I remember in PASCAL you had to use a loop that searched through every control, but I can't for the life of me figure out how to do it in Java.
This example is basically a very simplified version of what I want to do, but any help understanding the concept behind it would be greatly appreciated.
Thanks for readin',
-shurgsLast edited by shurgs; 08-12-2010 at 01:51 PM.
- 08-12-2010, 01:33 PM #2
Senior Member
- Join Date
- Aug 2010
- Posts
- 127
- Rep Power
- 0
I'm no expert, but my suggestion would be to use a switch statement if there aren't that many textfields, so:
switch(i){
case 0: print in textfield1
case 1: print in textfield2
etc.
}
-
You could place the JTextFields in an array and then simply use i as the array index. Other options are to use a List or a Map.
- 08-12-2010, 01:45 PM #4
Member
- Join Date
- Aug 2010
- Location
- England
- Posts
- 12
- Rep Power
- 0
Thanks for the reply. I hadn't thought of that actually and it's a good suggestion, but as you say, I'm not sure it would scale up well. There's going to quite a few and I need to loop through them systematically, pulling data from a MySQL database and putting it in the text fields.
- 08-12-2010, 01:49 PM #5
Member
- Join Date
- Aug 2010
- Location
- England
- Posts
- 12
- Rep Power
- 0
An array would work beautifully actually. It kinda seems obvious now that you've said it :D
Thank you all for your replies.
-shurgs
-
I wonder if you need to use a JTable instead?
- 08-12-2010, 01:54 PM #7
Member
- Join Date
- Aug 2010
- Location
- England
- Posts
- 12
- Rep Power
- 0
jTables and Tabel Models confuse the hell out of me, especially with the Swing GUI editor, because it makes it so bloomin' awkward to edit the code. A terrible reason to use something else and bad practice, I know, but I'm hoping this will work out better in the end anyway for what I want to achieve. Hehe.
I just thought of something. To place them into an array I would have to loop through the controls anyway, unless I did it manually, but that would just be silly. Kinda puts me back to square one. :)
Maybe I should just bite the bullet and try tables again.Last edited by shurgs; 08-12-2010 at 01:56 PM. Reason: I'm an idiot.
Similar Threads
-
Dynamically changing the title of the JFrame??
By Y. Progammer in forum New To JavaReplies: 2Last Post: 03-15-2010, 09:20 AM -
Dynamically changing the TextArea.forground !
By Y. Progammer in forum New To JavaReplies: 6Last Post: 03-01-2010, 10:08 AM -
loading .properties file dynamically
By nanaji in forum Advanced JavaReplies: 3Last Post: 03-17-2009, 03:40 AM -
Dynamically changing the display
By abhiN in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 01-22-2008, 11:19 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks