key-bindings

Java: Moving an object at an angle and changing angle with KeyPress

天涯浪子 提交于 2019-12-02 05:17:46
Ok, so what i want is the rectangle to always be moving, but when you press the left and right arrow is changes the direction by either increasing or decreasing the angle. With this code the sqaure moves as it should in the correct direction, but when i press the keys the direction does not change. import java.awt.*; import java.awt.Color; import javax.swing.Timer; import javax.swing.*; import java.awt.Graphics; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.KeyListener; import java.awt.event.KeyEvent; import java.awt.event.KeyAdapter; public

KeyListeners vs Keybindings? [duplicate]

混江龙づ霸主 提交于 2019-12-02 02:57:06
Possible Duplicate: Comparing functionality between KeyListeners and Key Bindings I've been trying to use the KeyListener in my program in order to get the input for constructing a number. It doesn't work as far as I can tell even though i've fully implemented it but thats not the question :P. Anyway, I searched the internet in order to see if I was doing something wrong and came across Keybindings which are apparently made to work with swing components as opposed to KeyListeners. Which would be better for just getting the input from the number keys? The Keylistener is an older interface from

C# how to disable keybinding

我的未来我决定 提交于 2019-12-02 01:05:29
The MenuItem control has the convenient property IsEnabled (inherited from UIElement ). This allows me to, when appropriate, hide the command exposed by that menu option. But if that command is also bound to a key (e.g. Ctrl+K), the user can still access it. How do I get the IsEnabled functionality to a KeyBinding ? If you bind the KeyBinding to an ICommand , you can just set the ICommand.CanExecute to false (and potentially raise CanExecuteChanged ). This will "disable" the KeyBinding since the command itself will be disabled. 来源: https://stackoverflow.com/questions/15706070/c-sharp-how-to

How do I prevent arrow key press in JTextField from scrolling JScrollPane?

╄→尐↘猪︶ㄣ 提交于 2019-12-02 00:46:25
I'd like to add a custom arrow key listener for my JTextField . But looks like the arrow keys are bound to the JScrollPane on which I put my text field. How do I unbind them? You could try replacing the key bindings on the scroll pane, but it might make sense to keep them to allow the user to scroll the pane when they are not focused in your text field. Instead, you can add key bindings to the text field that do nothing, which will consume the event and prevent them from begin sent to the scroll pane, for example.... import java.awt.BorderLayout; import java.awt.Dimension; import java.awt

Why can't I get KeyEvent.VK_TAB when I use Key Binding for a JPanel

≯℡__Kan透↙ 提交于 2019-12-01 22:19:33
I will print related info if users focus on current window and press a key. However, it works for some keys like 'a' but not for 'tab'. Here is a simple demo: import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import javax.swing.AbstractAction; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.KeyStroke; public class KeyBindingTest { public static void main(String[] args) { KeyBindingTest test = new KeyBindingTest(); test.createUI(); } public void createUI(){ JFrame frame = new JFrame("KeyBinding

Responding to Button using KeyBIndings

允我心安 提交于 2019-12-01 21:30:26
I want to make a program with these goals: 1) Make a JButton 2) Attach the button to a key (The "A" Key) using KeyBindings 3) Execute some code when "A" is clicked Here is the code I have so far: // Imports Public class Test{ JButton button = new JButton(); //... Test(){ button.getInputMap().put(KeyStroke.getKeyStroke("A"), "Pressed"); //... } // Where do I add the code that responds when button is pressed? } Now where do I add the code that I want it to execute when the button is pressed? you need to add an action listener, specificaly for actionPerformed. declare this somewhere inside your

Multiple KeyBinding like Visual Studio in WPF

拟墨画扇 提交于 2019-12-01 20:20:27
问题 I have tried to read many posts on StackOverflow about how to implement the KeyBinding like Visual Studio Ctrl+Shift+ A or Ctrl+K,Ctrl+C but no luck I have found this article on on blogspot regarding Multiple Keybinding but it makes multiple gesture like Ctrl + A,B Is it possible to make a Keybinding that flexible like (VS Studio) through XAML Syantax. 回答1: Sequence key combo's like VS has are not natively part of WPF and most other UI frameworks. The reason being that such combos hail from

Custom emacs-like key bindings on os x: DefaultKeyBinding.dict not working as expected

余生长醉 提交于 2019-12-01 20:12:51
I'm trying to add to the emacs-like key bindings in OS X 10.7.5. In particular, in the default key bindings, alt-d and alt-b insert special characters, while I would like them to delete a word and move back a word. I've created a file ~\Library\KeyBindings\DefaultKeyBinding.dict with the following content: { "~d" = "deleteWordForward:"; } (as suggested in the answers to this question ) and opened a new terminal window (I tried rebooting, too) but now the alt-d combination just beeps at me, and does nothing else. Any clues? lawlist This should do the trick -- within the Terminal.app Keyboard

Full screen Window won't get keyboard input using KeyListener or KeyBoardFocusManager

跟風遠走 提交于 2019-12-01 16:54:58
I'm having problems with getting my KeyBoardFocusManger to work with my full screen Window . No matter what, it just wont get keyboard input. I used a System.exit(0) and a println() to look for any call to the keypressed/released/typed method, but no errors are thrown. I've tried KeyListeners ; but after I read this , I changed to a KeyboardFocusManager , and the same thing still happens. I'm really getting desperate; from what I can judge, the Window is not getting focus of the keyboard? Here is my main: public static void main(String[] args) { EventQueue.invokeLater(new Runnable() {

How to set a Single key Mnemonic in button in Java?

拜拜、爱过 提交于 2019-12-01 15:33:48
I am working on a project and I want to set Mnemonic on buttons. But the problem is Mnemonic works on pairing key example ( Alt + F ) etc. But I want it to be on single key. mKorbel have look at KeyBindings, then you can to attach any Key to the JButton Here is one example code for your help, just Press C on the Keyboard : import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.Action; public class ButtonExample { private JFrame frame; private JButton button; private void displayGUI() { frame = new JFrame("Button Mnemonic Example"); frame.setDefaultCloseOperation