I am creating a help system that uses links (JButton extension) that extend and collapse subpanels with JLabels in them. Links and dashboards work, but I am unable to implement the search dialog. I want to highlight parts of the text for which the user is looking. I think that using text attributes to underline text in links is related to my ability to highlight parts of the text, but I'm not sure how to do it differently. Here is the code for my Link class, which is my subclass of links:
public abstract class Link extends JButton { private static final int SPACE = 5; private static final Color TEXT_COLOR = Color.BLUE; public Link(String text) { super(text); setBorder(BorderFactory.createEmptyBorder(SPACE, SPACE, SPACE, 2 * SPACE)); setContentAreaFilled(false); setFocusable(false); setForeground(TEXT_COLOR); Map<TextAttribute, Integer> underlineAttribute = new HashMap<TextAttribute, Integer>(); underlineAttribute.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); setFont(getFont().deriveFont(underlineAttribute)); } }
How can I implement text highlighting in my links without getting rid of underlining? Do I need to change them for a subclass? Thanks, advanced!
source share