I'm working on a project and have become stuck. I want to display the contents of an arraylist as a series of adjacent, underlined pieces of text that execute some code when you click on them. I initially displayed the contents as a row of JButtons (with border set to null and editable false). They were quite large however, and I wanted the text to be close together. I tried reducing the size of the JButton using setSize, but whenever its size was set beneath a certain value, the text on the button changed into "...", even though there was blatantly more than enough room to fit the text on. Reducing the font size of the text did not help either.
I'm now trying to use a JTextField (with border set to null and editable false) to display the contents. Although it is possible to add an ActionListener to this, I cannot figure out how to catch the events it generates. The only one i'm interested in is when the mouse is clicked on it. I presume it generates an event because it highlights the current contents of the textfield. I realise it is possible to do this by adding a MouseMotionListener and detecting its clicks, but i was wondering if there was a simpler way.
Is there any way to do this or should I try creating hyperlinks with a jeditorpane?