Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 555633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:50:06+00:00 2026-05-13T11:50:06+00:00

I have a JButton that is constructed using an Action and this action has

  • 0

I have a JButton that is constructed using an Action and this action has a name that is contains html.

I then go about setting the mnemonic on the JButton by first parsing out html to get the first character in the name.

For example, the JButton name might be "<html>Test<br>Button</html>", so after parsing the html the mnemonic key should be “T”.

So now when the JButton is rendered I can push alt-T to activate the button, however the underline mnemonic indicator on the T is not present.

Would anyone know a way to get this to occur?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:50:06+00:00Added an answer on May 13, 2026 at 11:50 am

    It is unclear to me what you mean by “setting the mnemomic on the JButton by parsing html”. The mnemonic can be set on a JButton by calling the method setMnemonic in the JButton class. I tried below piece of code and when I press Alt+P I get the message I am pressed printed in the console.

    public class HTMLButton extends JPanel implements ActionListener {
        JButton     b1;
        public HTMLButton() {
            super(new BorderLayout());
            b1 = new JButton("<html><b><u>P</u>ress</b></html>");
            b1.setMnemonic(KeyEvent.VK_P);
            b1.addActionListener(this);
            add(b1);
        }
    
        public void actionPerformed(final ActionEvent e) {
            System.out.println("I am pressed");
        }
    }
    

    Also see the section How to Use HTML in Swing Components in the Java tutorial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JButton that has a callback function like so: myJButtonCallBackFunc (ActEvtListener evt)
I have this tiny flag that I am using for an icon on the
I have a jButton that calls a function. This function can take up to
I have a class that extends javax.swing.JPanel , it contains a single JButton. I've
I have this code: public class Window extends JFrame { public Window(){ ... JButton
I have a JLabel, a JButton, and a JTextField all arranged horizontally in that
I have a custom button class called ImageButton that extends JButton. In it i
I have a JButton that I would like to change the background color of
I have a class that extends JButton because the custom look and feel I'm
I have a JButton that when i click on it, i load some data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.