Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2282 > unrolled thread

menu accelerator

Started by"Chameleon" <chameleon@THRWHITE.remove-dii-this>
First post2011-04-27 15:38 +0000
Last post2011-04-27 15:38 +0000
Articles 5 — 3 participants

Back to article view | Back to comp.lang.java.gui


Contents

  menu accelerator "Chameleon" <chameleon@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
    Re: menu accelerator "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
      Re: menu accelerator "Chameleon" <chameleon@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
        Re: menu accelerator "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
          Re: menu accelerator "Chameleon" <chameleon@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000

#2282 — menu accelerator

From"Chameleon" <chameleon@THRWHITE.remove-dii-this>
Date2011-04-27 15:38 +0000
Subjectmenu accelerator
Message-ID<faa2al$f5p$2@volcano1.grnet.gr>
  To: comp.lang.java.gui
I use netbeans.
In "Build" menu there is an action named "Stop Build/Run".
I assign to this JMenuItem the accelerator "Escape".
In "Build" menu there is an action named "Build Main Project".
I assign to this JMenuItem the accelerator "F7".

How I this possible in Java?
I try this in my programs MANY times but nothing.
Single keys doesn't work like accelerators.
They need a modifier key.

So, how the netbeans do this?

thanks

PS: I want to add an "F1" accelerator to menuitem:   help->help index

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#2288

From"Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this>
Date2011-04-27 15:38 +0000
Message-ID<76fa6b434bd20@uwe>
In reply to#2282
  To: comp.lang.java.gui
Chameleon wrote:
>I use netbeans.

Do you use it, or does it use you?
It's just that it seems to have more control 
at the moment, than you do.  

<snip boring crap about your IDE..>

>How I this possible in Java?

By learning how to code the Java programming 
language.  There is a good reference here.
<http://java.sun.com/docs/books/tutorial/>

>I try this in my programs MANY times but nothing.

What 'programs'?  Paste an SSCCE here and we
might be able to see what you are doing wrong,
otherwise all I can suggest is "change the dot to 
a comma in column 47 of line 53" - that *might*
solve the problem (and if it does, buy a lottery ticket
quickly - such luck cannot last).

>So, how the netbeans do this?

Probably the same way as 'native' Java code.

Did you even bother checking the Java code that
your IDE produces?  Or are you just expecting us
to spoon-feed the information to you?  Information
that could be obtained by consulting the relevant 
section of the Java Tutorial, or sometimes even
the JavaDocs..  

.Wait a second, I have to run and get a fork to 
mash up the potato - suitable for spoon-feeding.

-- 
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-gui/200708/1

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#2293

From"Chameleon" <chameleon@THRWHITE.remove-dii-this>
Date2011-04-27 15:38 +0000
Message-ID<fad4ot$i7l$1@volcano1.grnet.gr>
In reply to#2288
  To: comp.lang.java.gui
>> I use netbeans.
> 
> Do you use it, or does it use you?
> It's just that it seems to have more control 
> at the moment, than you do.  
> 
> <snip boring crap about your IDE..>
> 
>> How I this possible in Java?
> 
> By learning how to code the Java programming 
> language.  There is a good reference here.
> <http://java.sun.com/docs/books/tutorial/>
> 
>> I try this in my programs MANY times but nothing.
> 
> What 'programs'?  Paste an SSCCE here and we
> might be able to see what you are doing wrong,
> otherwise all I can suggest is "change the dot to 
> a comma in column 47 of line 53" - that *might*
> solve the problem (and if it does, buy a lottery ticket
> quickly - such luck cannot last).
> 
>> So, how the netbeans do this?
> 
> Probably the same way as 'native' Java code.
> 
> Did you even bother checking the Java code that
> your IDE produces?  Or are you just expecting us
> to spoon-feed the information to you?  Information
> that could be obtained by consulting the relevant 
> section of the Java Tutorial, or sometimes even
> the JavaDocs..  

I use netbeans because of real-time syntax checking and refactor things.
I do not use netbeans to generate code.

> .Wait a second, I have to run and get a fork to 
> mash up the potato - suitable for spoon-feeding.

aggressive message!
maybe because my english sucks and you cannot understand what I am 
trying to say.

btw, I am trying to say, how can I assign the "F1" accelerator to a 
menuitem. The following code doesn't work:
---------------------
JMenuBar jmb = new JMenuBar();
JMenu jm = new JMenu("Help");
JMenuItem jmi = new JMenuItem("Help Index");
jmi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
jmi.addActionListener(listener);
jm.add(jmi);
jmb.add(jm);
---------------------
I don't want "Shift+F1", "Ctrl+F1", etc. I want "F1".

Thanks

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#2295

From"RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this>
Date2011-04-27 15:38 +0000
Message-ID<46caa9a5$0$21098$da0feed9@news.zen.co.uk>
In reply to#2293
  To: comp.lang.java.gui
Chameleon wrote:
> Andrew Thompson wrote:
>>
>> Paste an SSCCE here and we
>> might be able to see what you are doing wrong,
> 
> I am trying to say, how can I assign the "F1" accelerator to a 
> menuitem. The following code doesn't work:
> ---------------------
> JMenuBar jmb = new JMenuBar();
> JMenu jm = new JMenu("Help");
> JMenuItem jmi = new JMenuItem("Help Index");
> jmi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
> jmi.addActionListener(listener);
> jm.add(jmi);
> jmb.add(jm);
> ---------------------
> I don't want "Shift+F1", "Ctrl+F1", etc. I want "F1".
> 

Thats not an SSCCE!

You have a bug in the code you are *not* showing us.

Here's a working SSCCE based on your snippet:
-----------------------------------------8<-----------------------------------
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;

public class TestAccellerator implements ActionListener {

     TestAccellerator() {

	// So I don't need to edit Chameleon's code at all
         ActionListener listener = this; // ick.

	// Chameleon's snippet *exactly* as in newsgroup
         JMenuBar jmb = new JMenuBar();
         JMenu jm = new JMenu("Help");
         JMenuItem jmi = new JMenuItem("Help Index");
         jmi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
         jmi.addActionListener(listener);
         jm.add(jmi);
         jmb.add(jm);
	// end of Chameleon's snippet

         JPanel p = new JPanel();
         p.add(new JLabel("Panel"));

         JFrame f = new JFrame("Test Accellerator");
         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         f.add(p);
         f.setJMenuBar(jmb);
         f.pack();
         f.setVisible(true);
     }

     public void actionPerformed(ActionEvent e) {
         System.out.printf("Event: command '%s' from object '%s'\n", e
                 .getActionCommand(), e.getSource());
     }

     public static void main(String[] args) {
         SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                 new TestAccellerator();
             }
         });
     }

}

-----------------------------------------8<-----------------------------------
When I press F1 I get the output I expected.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#2296

From"Chameleon" <chameleon@THRWHITE.remove-dii-this>
Date2011-04-27 15:38 +0000
Message-ID<faerfl$nen$1@volcano1.grnet.gr>
In reply to#2295
  To: comp.lang.java.gui
> Chameleon wrote:
>> Andrew Thompson wrote:
>>>
>>> Paste an SSCCE here and we
>>> might be able to see what you are doing wrong,
>>
>> I am trying to say, how can I assign the "F1" accelerator to a 
>> menuitem. The following code doesn't work:
>> ---------------------
>> JMenuBar jmb = new JMenuBar();
>> JMenu jm = new JMenu("Help");
>> JMenuItem jmi = new JMenuItem("Help Index");
>> jmi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
>> jmi.addActionListener(listener);
>> jm.add(jmi);
>> jmb.add(jm);
>> ---------------------
>> I don't want "Shift+F1", "Ctrl+F1", etc. I want "F1".
>>
> 
> Thats not an SSCCE!
> 
> You have a bug in the code you are *not* showing us.
> 
> Here's a working SSCCE based on your snippet:
> -----------------------------------------8<----------------------------------- 
> 
> import java.awt.event.ActionEvent;
> import java.awt.event.ActionListener;
> import java.awt.event.KeyEvent;
> 
> import javax.swing.JFrame;
> import javax.swing.JLabel;
> import javax.swing.JMenu;
> import javax.swing.JMenuBar;
> import javax.swing.JMenuItem;
> import javax.swing.JPanel;
> import javax.swing.KeyStroke;
> import javax.swing.SwingUtilities;
> 
> public class TestAccellerator implements ActionListener {
> 
>     TestAccellerator() {
> 
>     // So I don't need to edit Chameleon's code at all
>         ActionListener listener = this; // ick.
> 
>     // Chameleon's snippet *exactly* as in newsgroup
>         JMenuBar jmb = new JMenuBar();
>         JMenu jm = new JMenu("Help");
>         JMenuItem jmi = new JMenuItem("Help Index");
>         jmi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
>         jmi.addActionListener(listener);
>         jm.add(jmi);
>         jmb.add(jm);
>     // end of Chameleon's snippet
> 
>         JPanel p = new JPanel();
>         p.add(new JLabel("Panel"));
> 
>         JFrame f = new JFrame("Test Accellerator");
>         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>         f.add(p);
>         f.setJMenuBar(jmb);
>         f.pack();
>         f.setVisible(true);
>     }
> 
>     public void actionPerformed(ActionEvent e) {
>         System.out.printf("Event: command '%s' from object '%s'\n", e
>                 .getActionCommand(), e.getSource());
>     }
> 
>     public static void main(String[] args) {
>         SwingUtilities.invokeLater(new Runnable() {
>             public void run() {
>                 new TestAccellerator();
>             }
>         });
>     }
> 
> }
> 
> -----------------------------------------8<----------------------------------- 
> 
> When I press F1 I get the output I expected.


I dont know what is SSCCE but now I know.

Holy Sh*t!
F1 working!
I am dump and I spend your time for nothing!
I found a clause "if (key == 0 || modifier == 0) ..." in my code...
What a SHAME.
Sorry.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web