JButton text changes when an Action is set

Viewed 373

I am working on a swing GUI project and i have a JButton that turns text inside a JTextPane bold. I use an Action to do this.

Here's the code for the Action

public static Action boldAction = new StyledEditorKit.BoldAction();

Here's the code for the JButton

JButton bold = new JButton("B");
bold.setFont(new Font("Arial", Font.BOLD, 15));
bold.setBounds(393, 15, 100, 100);
bold.setBackground(Color.WHITE);
bold.setAction(boldAction);
frame.add(bold);

Without the Action included the text on the button is a bold "B", which is what I want. The issue that arises is that when I add in the action, it changes the text on the button to say "font-bold".

Why does this happen, and how can I fix this?

2 Answers
Related