I (very miraculously) answered my question when I wrote this question, but it was such a find that I wanted to share with everyone. I understand that these should be real "questions", but it was a monumental find for me. However, there is a “question” that can be answered.
I created my own class that extends JToggleButton. In this class, I delete all MouseListeners by default, so it will only accept mouse actions when I consider the object to be ready. The problem I encountered is to manipulate the JToggleButtons ImageIcon (set using setIcon ()). If the button did not appear on the screen (not visible due to JScrollPane), when I said that the button will be selected, ImageIcon will disappear. Similarly, if I changed ImageIcon when the button was selected, ImageIcon will also disappear.
It turns out that in my normal MouseListener I used getModel.setSelected (true) instead of getModel.setPressed (true). Apparently, I don’t have a clear understanding of the difference between the selected and the pressed, but suffice it to say that this fixed my problem. Therefore, my “question” will be an explanation of these two terms.
To summarize, do not use setSelected () on a button when you want to use setPressed (). What a pain to keep track of it! I sincerely hope this helps someone else. Email Mail is valid but spam.
source share