4

I have a group of JRadioButtons. Each of them points to a directory with only text files, when I mouse over them they should count how many files are in each directory and return the file count as tooltips, I can not set the tooltips when I created the buttons, how to get dynamic tooltips from them ?

I tried the following, but didn't work :

JRadioButton myButton=new JRadioButton("Test")
{
  public static final long serialVersionUID=26362862L;
  public String getToolTipText(MouseEvent evt)
  {
    return "123";
  }
}
Frank
  • 30,590
  • 58
  • 161
  • 244

1 Answers1

5

Override the getToolTipText() method of your radio buttons.

You can then use the File.listFiles(...) method to determine the number of files in the directory.

Edit:

It appears that when you override this method you need to manually register the component with the ToolTipManager:

ToolTipManager.sharedInstance().registerComponent(radioButton);
camickr
  • 321,443
  • 19
  • 166
  • 288
  • Great answer, thanks ! Wonder why registerComponent was decessary here, but it worked ! – Frank Jul 21 '13 at 01:46