Thursday, 15 March 2012

java - Iterate Through JPanel Components In Hashmap -



java - Iterate Through JPanel Components In Hashmap -

i've got hashmap of jpanel components , i'm trying iterate through , style, i've done in past jbuttons on jpanel i'm having problem getting jlabel-specific attributes. code i've got:

(component item : imageareas.values()) { // style components item.setborder(borderfactory...); }

the problem beingness there no setborder() attribute components, there way can cast component item jpanel in loop? - i've tried adding (jlabel) in front end of doesn't that. imageareas hashmap.

is there way can cast component item jpanel?

jpanel panel = (jpanel)item; item.setborder(...);

the above assumes indeed have jpanels in hashmap.

the question why utilize hashmap contains components, when can utilize hashmap contains jpanels? create hashmap can like:

hashmap<string, jpanel> imageareas = new hashmap<string, jpanel>();

then access panels can do:

for (jpanel panel : imageareas.values()) { panel.setborder(borderfactory...); }

java swing jpanel

No comments:

Post a Comment