Results 1 to 3 of 3
- 12-18-2009, 07:38 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 15
- Rep Power
- 0
Why doesn't this work? (multi-type array)
edits[] is an Object[] containing JTextFields and JComboBoxesPHP Code:for (int i = 0 ; i < edits.length - 5 ; i++){ if (edits[i] instanceof JTextField){ edits[i].setText(db.dbImport(fields[i]));} else{edits[i].setSelectedIndex(db.dbInt(fields[i])-mods[i]);}}
fields[] is a String[]
mods[] is an in[]
I get two compile errors:
cannot find symbol method setText(java.lang.String) on line three
cannot find symbol method setSelectedIndex(int) on line four
By all accounts, this SHOULD work. If the entry in edits[] is a JTextfield, it tries to set the text, if it's a JComboBox, it tries to set the index. What's wrong here? My only guess is that Object doesn't know how to interpret methods specific to it's subclasses, and if that's true, then how can I fix it?
Thanks in advance!
- 12-18-2009, 08:07 PM #2
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
try casting the edits to the desired Component like
Java Code:for (int i = 0 ; i < edits.length - 5 ; i++){ if (edits[i] instanceof JTextField){ ((JTextField)edits[i]).setText(db.dbImport(fields[i]));} else{ ((JComboBox)edits[i]).setSelectedIndex(db.dbInt(fields[i])-mods[i]); } }
- 12-18-2009, 09:56 PM #3
Member
- Join Date
- Dec 2009
- Posts
- 15
- Rep Power
- 0
Similar Threads
-
[SOLVED] Multi-dimensional Array further help
By thelinuxguy in forum Advanced JavaReplies: 4Last Post: 05-07-2009, 04:50 PM -
Refractoring a Multi-Dinmension array
By thorne_ in forum New To JavaReplies: 4Last Post: 04-15-2009, 06:30 PM -
Multi-dimensional array
By VinTiger in forum New To JavaReplies: 22Last Post: 03-01-2009, 06:51 AM -
Multi dimensional Array
By Preethi in forum New To JavaReplies: 1Last Post: 07-09-2008, 03:34 PM -
Help with array multi-dimensional
By barney in forum New To JavaReplies: 1Last Post: 07-31-2007, 08:00 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks