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 5845091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:23:07+00:00 2026-05-22T12:23:07+00:00

menuBar = new JMenuBar(); // File Menu JMenu fileMenu = new JMenu(File); menuBar.add(fileMenu); //

  • 0
menuBar = new JMenuBar();
// File Menu
JMenu fileMenu = new JMenu("File");
menuBar.add(fileMenu);
// File->New
JMenuItem newMenuItem = new JMenuItem("New");
frame.setJMenuBar(menuBar);
newMenuItem.addMouseListener(new MouseAdapter() {
    @Override
    public void mousePressed(MouseEvent arg0) {
        btnExample.setText("Clicked");
        btnExample.doClick();
    //---------->SOME HOW TO EXECUTE btnExample<---------//
}
});
fileMenu.add(newMenuItem);

final JButton btnExample = new JButton("SD");
frame.getContentPane().add(btnExample, "cell 4 0,growx,aligny top");
btnExample.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent arg0) {
    spinnerForVar.setValue(4);//default value for spinner
    spinnerForFunc.setValue(4);//default value for spinner
    ...             
  }
});

Hello! I hope someone can help me. Here it is the problem: I have Menu item “New” and have button btnExample. I want the following: When i click on “File->New” it executes btnExample. My code is able only to change the button title and show visual affect of clicking. But how can I actually execute it?

  • 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-22T12:23:08+00:00Added an answer on May 22, 2026 at 12:23 pm

    I have only one advice – don’t do that. Don’t bind GUI components in this way.

    If you want two components to execute the same operation, simply pack this operation in a method and call the method from both components.

    Also, use ActionListener – are you sure the user is going to press it using mouse and not keyboard? what if you add shortcuts to those buttons/components?

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

Sidebar

Related Questions

Here is the code I am using: JMenu menu = new JMenu(Menu); JMenuItem item
Im creating a dynamic MenuBar from xml file, and binding events to menu items
import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; @SuppressWarnings(serial) public class Main extends JFrame
I'm pretty new to HTML and CSS. I'm making a menu bar horizontal and
I am using MenuBar from GWT showcase. I want to add text in the
I have an application that lives in the menubar, without a main menu or
I'm trying to create a two-level horizontal navigation menu (or menubar) that displays the
Any idea why the menu bar menuBar is not showing? everything looks fine to
import org.jdesktop.application.SingleFrameApplication; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem;
I have a JMenu and when a person clicks on a JMenuItem I want

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.