Skip to main content

JToggleButton tooltip text

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
hrizwan
Offline
Joined: 2011-01-13

Hello,
I am having a difficult time to get the tooltip text to change when the button is disabled.
For example I have the following code:
private JButton b;
b = new JButton(new ImageIcon(filename));

b.setModel(new JToggleButton.ToggleButtonModel());
ImageIcon lPressedIcon = new ImageIcon(otherfilename);
b.setSelectedIcon(lPressedIcon);

if (b.isEnabled())
b.setToolTipText("pause");
else
b.setToolTipText("play"));
b.setDisabledSelectedIcon(lPressedIcon);
b.setSize(lButtonSize);
b.setMinimumSize(lButtonSize);
b.setMaximumSize(lButtonSize);
b.setPreferredSize(lButtonSize);
b.addActionListener(this);
b.setEnabled(true);
Whether I select the button or unselect it (click it twice), I still get the "pause" tool tip text. What do I do so that when I select the button I get the "pause" tooltip text and when I deselect it I get the "play" tooltip text. Instead of b.isEnabled() statement I have also tried b.isSelected(). That still doesn't work.
Thanks in advance

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
hrizwan
Offline
Joined: 2011-01-13

ahhh nevermind, fixed it.

Thanks