JMenu fileMenu = new JMenu("File"); fileMenu.setText("New"); // sets the text of the menu to "New"
JMenu editMenu = new JMenu("Edit"); JButton boldButton = new JButton("Bold"); boldButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (boldButton.getText().equals("Bold")) { boldButton.setText("Unbold"); } else { boldButton.setText("Bold"); } editMenu.setText(boldButton.getText()); // updates the text of the menu // ... } }); editMenu.add(boldButton);Here, when the "Bold" button is clicked, it changes its text to "Unbold" and updates the text of the editMenu JMenu. Package/library: javax.swing