How to get RadioButton dynamic hint in Java?

I have a group of JRadioButtons. Each of them points to a directory with only text files, when I am above them, they should count how many files are in each directory, and return the number of files as hints, I can’t set the tooltips when I created the buttons, how to get dynamic clues from them?

I tried the following but did not work:

JRadioButton myButton=new JRadioButton("Test") { public static final long serialVersionUID=26362862L; public String getToolTipText(MouseEvent evt) { return "123"; } } 
+4
source share
1 answer

Cancel the getToolTipText() method of your switches.

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

Edit:

It seems that when overriding this method, you need to manually register the component using ToolTipManager:

 ToolTipManager.sharedInstance().registerComponent(radioButton); 
+5
source

Source: https://habr.com/ru/post/1492470/


All Articles