jmenuitem

JMenuItem: how to set an Accelerators with 3 keys?

谁都会走 提交于 2019-12-13 13:22:23
问题 Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MenuActions extends JFrame { private JMenuBar jmb; private JMenu file; private JMenuItem open; public MenuActions() { jmb = new JMenuBar(); file = new JMenu("File"); open = new JMenuItem("Open"); open.addActionListener(new MenuAction()); open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,KeyEvent.VK_P,ActionEvent.CTRL_MASK)); file.add(open); jmb.add(file); this

What listener should I use? (Java)

混江龙づ霸主 提交于 2019-12-13 07:56:49
问题 I want a listener that defines if a JMenuItem was selected. Not pressed, but just highlighted. I don't need MouseOver listener, because the selection is supposed to be performed from keyboard. What listener should I use? Thanks in advance :) 回答1: I would guess you add a ChangeListener to the ButtonModel of each JMenuItem. 回答2: You should use addActionListener. See also this question. 来源: https://stackoverflow.com/questions/5821701/what-listener-should-i-use-java

Java - Add accelerator to a JMenuItem

↘锁芯ラ 提交于 2019-12-12 23:00:26
问题 I want to set an accelerator to a JMenuItem. Right now I am setting it like this openFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); and it's working but I don't want ctrl+o as accelerator. I want 'space' as accelerator but I didn't find any method by which I can generate a KeyStroke corresponding to 'space'. KeyStroke.getStroke() either takes a char or (int, int). I didn't find any char corresponding to space also. 回答1: ..didn't find any char corresponding

JMenuItem accelerator not working when menu bar is hidden

不问归期 提交于 2019-12-12 18:41:35
问题 This question is a follow-up to this question. I have a JMenuBar whose behavior is like the menu bars in Firefox and iTunes. That is, the menu bar is initially hidden, but when you press Alt , the menu bar appears. The answer to the other question solved the problem of achieving that functionality, but it brought about another issue: The JMenuItem accelerators are not working when the JMenuBar is not visible. In other words, you must press Alt before CTRL+F (the installed accelerator) will

Is it possible to remove a JMenuItem from a JMenu given only the String associated with the JMenuItem

百般思念 提交于 2019-12-12 03:05:16
问题 I have a JMenu populated with JMenuItems from a database that have listeners, one of them being to delete the entry from the database if selected. When this happens that JMenuItem should disappear from the menus. Here's a short bit as an example for (final Racer r : Racer.getAllRacers()) { JMenuItem j = new JMenuItem(r.getName()); racerDelete.add(j); j.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int reply = JOptionPane.showConfirmDialog(null, "Are you

Add accelerator description to JMenuItem in GUI, without actually adding an accelerator

假装没事ソ 提交于 2019-12-12 01:36:54
问题 I'm trying to set some text to be displayed where the accelerator binding is usually displayed, for a JMenuItem . The demarcated Ctrl+Z text in the following image is an example of what I'm trying to set, for another JMenuItem . I don't actually want to set an accelerator for this JMenuItem , though. I've poked around the source for several classes, like JMenuItem and BasicMenuItemUI , to no avail. What's the simplest way to achieve this? Thanks in advance :) 回答1: I assume the reason you want

Java setPressedIcon not working

巧了我就是萌 提交于 2019-12-11 23:19:46
问题 I have menu in my application, and I want to set menu item normal state icon, and pressed state icon. Normal state icon is added, but when I press menu item, normal state icon is not changed by pressed state icon. What is problem here: JMenu m=new JMenu(text); m.setBackground(getTheme().colors.menuColor()); m.setOpaque(false); m.setIcon(core.getIcon(text, "normal")); m.setPressedIcon(core.getIcon("webmaps", "pressed")); 回答1: This issue has been seen before. The inherited setPressedIcon does

Change the title text of JMenuItem upon click?

 ̄綄美尐妖づ 提交于 2019-12-11 12:23:59
问题 I am adding a JMenuItem (Show History) that will toggle the appearance of a JPanel upon click. But after doing so, I want to change the title of that menu item to state the opposite action (Hide History). Is there a way to change just the text for that menu item, or must I remove the old JMenuItem and add a new one? JMenuItem history = new JMenuItem("Show History"); history.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //code here to show the history /

How to remove the space in JMenu Items

血红的双手。 提交于 2019-12-11 11:12:32
问题 As of now, I have this And this is my source code for MyFrame1 : import java.awt.EventQueue; import java.awt.GridLayout; import java.awt.Insets; import java.awt.Color; import java.awt.Color.*; import java.awt.Font; import java.awt.Font.*; import java.io.*; import java.io.BufferedReader; import java.io.FileReader; import javax.swing.JLabel; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax

AudioInputStream() does not stop

半城伤御伤魂 提交于 2019-12-11 06:32:23
问题 I have inserted a background audio into my program using AudioInputStream . When I press the On , the background audio will play, and Off will stop playing the background audio. Here is the part of my code for the audio playing part : public void playSound(int i) { try { . //Others buttons sound . //Others buttons sound if(i == 3 || i == 4) { AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("Background.wav")); Clip clip3 = AudioSystem.getClip( ); clip3.open