MILIND_JOG
asked on
Change label text dynamically
Dear Expert,
I have a string array and a pannel with buttons. I want to change label text of button with array values. I do not want to make it happen through button.setText methode. I want to achieve it dynamically.
Please help and suggest the solution.
Regards
I have a string array and a pannel with buttons. I want to change label text of button with array values. I do not want to make it happen through button.setText methode. I want to achieve it dynamically.
Please help and suggest the solution.
Regards
Dear Expert,
Spot on. And as he says, that's the method you are going to end up using. The only other thing that occurs to me that you might mean is that text changes on a mouseover. In which case, you could use a MouseInputAdapter. Although you might also need MouseInfo from the awt too.
ASKER
Thanks for instant comments. I mentioned that I do not want to use Button.setText methode. I mean to say that insted using setText on every button, I want to make it happen in loop using Component of Panel so as to avoide setText method for every individual Button.
Regards
Regards
Yes, you can use a loop, but again, setText would be used nonetheless. Typically if you have a large number of components where there is a pattern in one of the attributes (in your case, the text) then you can use an array of Component
ASKER
Component[] jp1 = jPanel1.getComponents();
for (Component component : jp1){
component.setEnabled(false );
}
using above code, I wanted to set component text and label values. I am unable to achieve the same. I am unable to get such setText or setLabel methodes. I am able to get only setName which is of no use for me. If notthing can be done than no matter I have already done it on individual Button basis.
Regards
for (Component component : jp1){
component.setEnabled(false
}
using above code, I wanted to set component text and label values. I am unable to achieve the same. I am unable to get such setText or setLabel methodes. I am able to get only setName which is of no use for me. If notthing can be done than no matter I have already done it on individual Button basis.
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks CEHJ. I will make necessory changes and will come back to you again.
Regards.
Regards.
ASKER
Thanks CEHJ for your great support.
Regards
Regards
:)