I want to make a java application, that will contain some text. I want some of these words to act like buttons. My idea is to put all the text in a text panel and the words that I want to act like buttons to be buttons. But i cant get a button to have the same style as the text. The button its always lower than the text from that line. It's possible to fix that ? Ty.
Example:
John went to the shop.
"shop" is a button and can be clicked, and it looks exactly like the other words.
My problem: I can't find how to make a JButton look like the other words.
You could just add a mouse listener to your JLabel with your text. That would respond to a mouse click action. You could also had a hover listener to change the border to give your user some indication that the text is clickable and remove the border when you are no longer hovering.
final JLabel lblNewLabel = new JLabel("Click Me!");
lblNewLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0)
{
System.out.println("Label Clicked!");
}
@Override
public void mouseEntered(MouseEvent e)
{
lblNewLabel.setBorder(BorderFactory.createEtchedBorder(1));
}
@Override
public void mouseExited(MouseEvent e)
{
lblNewLabel.setBorder(null);
}
});