I am Swing novice. I made a small app using JTree, JCheckBox, JList and JButton. I am using the associated model classes to store the presentation state. Works fine, except for the JButton. I’d like to update the button’s text according to a property of my model. Basically, it will change from log in/to log off whether the user is currently logged in. Unfortunatly, I can’t find a setText method in the ButtonModel interface. Can anybody tell me how to do this ?
Thanks. PW.
For a
JButtonyou can use anActionas your model. TheActioninterface defines keys which are used by theJButtonto retrieve its state from theAction, including one for the text:Action.NAMEIf you look at the source code, the constructor with the
Action(or simply thesetActionmethod) uses more information from theActionthen what can be retrieved from aButtonModel. Same for other constructors, e.g.So it seems that you are correct in your assessment that the
ButtonModeldoes not contain all information used to visualize a typicalJButton