'Enter' key listener!
When I press a button (mouse clik on the button) my application makes something (!). How can I do that the application to make the same thing when I pres 'Enter' key? I used accelerators and key listeners but it does work how I want. More informations: I have a JComboBox and when I write something in it and I press a button (or 'Enter' - I want...) the application adds items in this JComboBox...
hello,
u dont need to to use any keylistener, just add an actionlistener to the component and the enter key will be enabled. so if u want to enable it on the combobox than u will do something like:
comboBox.addActionListener(new ActionListener()
public void actionPerfored(ActionEvent e)
//your actions here
);to enable the enter key on a form, u could make use of this code:
UIManager.getDefaults().put("Button.focusInputMap", new
UIDefaults.LazyInputMap(new Object[] {
"ENTER", "pressed",
"released ENTER", "released"
}));asrar
Similar Messages
-
How to add a listener for enter key
I'd like to build a chatzone applcation just like msn. The application
has two textarea, one is for the messages sent and recieve and one is
for the message typing area. Just like MSN, I'd like to send the text
after the user pressed enter key. But my problem is I don't know how
to make a key listener. I've tried jTextArea1.addKeyListener() but I don't
know how to use it. Anyone can help me?
Thanks in advanceKeyListener is just an interface, so you could use:
public class MyKeyListener implements KeyListener
private JTextArea area = null;
public MyKeyListener (JTextArea area)
this.area = area;
// Don't care about a key being pressed.
public void keyPressed (KeyEvent e) {}
// Don't care about a key being typed.
public void keyTypes (KeyEvent e) {}
// We care about the key being released.
public void keyReleased (KeyEvent e)
// Check what key it is. Note sure if \n is the right one...maybe use the key codes.
if (e.getKeyChar () == '\n')
// The return key has been pressed and released, they really meant to press it!
// Get the last line of the text from the text area. This bits up to you...maybe
// store the last location of the caret and then read from that point up
// to the current point...
}You can also use a DocumentListener if you are using a JTextArea but this is a little bit more complex but may be better, DocumentListeners work on telling you about more macro changes to the document... -
Prevent Enter key from proceeding movie
I am using this code to get the user to enter the answer 16
in an input text field. It works but if the user hits the enterkey
after they've gotten the question right, the playhead starts and
moves to incorrect. This is not happening only in the testing
environment, the published file continues when Enter is pressed.
Can anyone help?
keyListener = new Object();
keyListener.onKeyUp = function() {
if (input_txt2.text == "16" and Key.getCode() == 13) {
//13 is key code for 'Enter'//
gotoAndPlay("1_3_13a");
_root.answer1 = "Correct!";
} else if (input_txt2.text != "16" and Key.getCode() == 13)
//13 is key code for 'Enter'//
_root.answer1 = "Incorrect.";
gotoAndPlay("1_3_13b");
Key.addListener(keyListener);I'm not following what "…activated when the enter key
is pressed even after the event has occurred." means. You mean that
even after this first entry you press enter and the value of
input_txt2.text != "16" so it is jumping to 1_3_13B?
I think I know what you mean, maybe. Notice how you are
setting up a listener? Well it keeps listening, it isn't a one time
deal. It listens for a keyUp until you tell it to stop. So just
because it works once why would you expect it to stop working? :)
What you need to do is either inside your conditionals or
perhaps just inside the onKeyUp function put a
Key.removeListener(keyListener); to tell it to stop listening. If
you are doing some kind of remediation at 1_3_13b and then want
them to have another try, perhaps you will want to leave the
listener or you might want to remove it and then add it back. I
don't know the exact structure of what you are doing, but I hope
this points you in the correct direction. -
Using the enter key on an editable table
Hi,
I'm using 11g adf and I can't figure out how to get past this:
When going through an editable table (with editingMode="editAll") using the enter key, it will stop after a certain number of rows, equal to the value of fetchSize. If I want to go down further, I have to scroll down another way to make it fetch the next set of rows, it won't go to the next row with the enter key. It simply won't execute the query to fetch the next rows.
Increasing the fetchSize will just delay the problem to a row further down (and decrease the performance since the fetch operation can take quite a bit longer).
I've tried to put a clientListener on both the table or the inputText fields to intercept the enter key, but that won't work when the table is in editable mode.
Is there any way to fix this problem?Hi,
I've tried to put a clientListener on both the table or the inputText fields to intercept the enter key, but that won't work when the table is in editable mode.
The clientListener needs to be on the inputText fields. Then in JS you need to call a server listener which will check if the current row is already at the range end and if calls NextSet (you can provide this as a method binding). Unfortunately after this you will need to PPR the table to show the new rows. This is how I would try it.
Frank -
Flex 4 does not dispatch keyboard events for ENTER key.
Hello everyone. I think I have a strange problem with Flex 4 Beta (4.0.0.8909). My application has had event listener for keyUp event for a month now and suddenly (two days ago) I've noticed that keyUp event is not dispatched for ENTER (ALT also) key. Anyone know why? By the way, I've tried this with keyDown event, also 4.0.0.8847 version of SDK - still the same: no keyboard events for ENTER (and ALT) key.
Here is the sample application that has got this issue:
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"
minWidth="640" minHeight="480"
keyUp="application1_keyUpHandler (event)">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
protected function application1_keyUpHandler (event: KeyboardEvent):void
Alert.show ("Key up: " + event.keyCode);
]]>
</fx:Script>
<s:layout>
<s:BasicLayout/>
</s:layout>
<s:TextArea verticalCenter="0" horizontalCenter="0" width="200"/>
</s:Application>
If you run this application and try typing anything in a TextArea you will get alerts with key codes. However, if you press ENTER (or ALT), you will get no alert.
I'm pretty sure the code above is right so that means there is a bug in latest nightly builds of SDK (i would swhitch to an older build if i knew which one does not have this bug).
Any ideas?Flex harUI wrote:
That's true, but in this case, I think the text editing code is eating ENTER key in order to prevent parents from seeing it and acting on it (like a submit button). We'll see if we can find a way around that.
You can get the ENTER key now by listening in capture phase.
Alex Harui
Flex SDK Developer
Adobe Systems Inc.
Blog: http://blogs.adobe.com/aharui
The enter key isn't being disposed of by textedit, the attached example code works without error if you a- remove the alert box and b-set the focus to your text area on initialisation. I agree that pressing the enter key then calling a dialog box will result in the enter key being "gobbled up" as the enter key is overridden by the dialog box code.
I think the first suggestion should be to anyone don't use dialogboxes for testing code. If for some reason debugging isn't desirable instead of a trace statement a simple label can be used as a 'fake' trace.
David
Message was edited by: David_F57: I worded this wrong, imho there is no need for a work around, the textarea component works as it should. When intercepting 'system' keycodes there is a need to consider the effect of the intercept and code appropriately to that end. -
JFileChooser - activating buttons with the enter key
Hi All,
I am trying to figure out how to activate the cancel button in the file chooser by tabbing to it, and than pressing the enter key. I know how to do this in a regular dialog, but I can't seem to get the access I need to the JFileChooser to get it to work there.
I would appreciate any help.
Thanks!
robinsteThe Buttons in the File Chooser by default dont use the Enter Key.
You must make the Enter key work if you are to use it
after you tab to get the focus on to it.
For this to be done you will need to extend the FileChooser
and change the key listener for the cancel button .......
Hope t was of some help ............ -
Navigate previous record,next record by entering key-up and key-down
Hi ,
JDeveloper11g_
I am trying to solve of how to navigate previous record,next record by entering key-up and key-down in ADF Table.
If any of you have this solution by JScript of Backing Bean please help me.
Thanks
zakir
===Hi zakir,
I hope I understood your requirements correctly. You have an editable ADF table. You would like to use the up/down arrow keys to move from one row to the next/prev row of the same column. Since the Tab key moves the cursor to the right and Shift+Tab moves it to the left, now you want to implement the same thing but just up and down, correct? If so, try this.
/** Javascript **/
function detectKey(evt) {
var inputText = evt.getSource();
var id = inputText.getClientId();
var start2 = id.indexOf(":") + 1;
var end2 = id.lastIndexOf(":");
var numValue = parseInt(id.substring(start2, end2));
var evt2 = evt.getNativeEvent();
arrows=((evt2.which)||(evt2.keyCode));
switch(arrows) {
// Up arrow
case 38:
numValue = numValue - 1;
break;
// Down arrow
case 40:
numValue = numValue + 1;
break;
var newStr = id.replace(/:\d:/, ':' + numValue + ':');
var comp = AdfPage.PAGE.findComponent(newStr);
if (comp != undefined) {
comp.focus();
/** Jspx. (Place a client listener on each inputText in the ADF table) **/
<af:column .....>
<af:inputText value="#{row.bindings.price.inputValue}" .....>
<af:clientListener type="keyDown" method="detectKey"/>
</af:inputText>
</af:column>With this, you get to move Up/Right/Down/Left in the editable ADF table without using the mouse.
References:
http://thepeninsulasedge.com/blog/?cat=29
af:clientListener attributes and methodes of event object in java script
Regards,
Chan Kelwin -
Flex4.5 SDK under Flash builder Burito doesnt dispatch Enter key event in Text Area anymore
Flex 4.5 under Flash builder Burito doesnt dispatch 'Enter' key event in Text Area anymore, in prev version 4.1 it was working properly, this stopped working after migration to Burito + Flex SDK 4.5?
What that suppose to be?Hi
That's true that Flex4.5 SDK under Flash builder Burito doesn't listen Enter key in Text Area for KeyUp or KeyDown event.
Here I found a work around you can use.
Add an eventlistener to the component in actionscript and set the useCapture=true next to eventlistener function. Now you can listen enter key for KeyUp or KeyDown Event
Hope this helps
Rush-me -
Clearing the TextArea texts when I press Enter key
How to clear the texts that I have typed into the TextArea when I press Enter Key?
I have now added a TextArea instance called input_txt to the stage and added an component event listener to detect when I press enter key. Then an event fires up which first reads the input to a string variable.
But next I need to automatically clear the texts in the TextArea.
How to do that?
function readInput(event:Event):void
input = input_txt.text;
trace(input);
// removing texts in the text input area-------- how?
input_txt.addEventListener(ComponentEvent.ENTER, readInput);
Please help.
Thank YouComponentEvent.ENTER occurs before the line feed is added to the text, and is not cancelable, so you'll probably need to set a flag and do the clearing in an Event.CHANGE handler. Something like this:
import fl.events.ComponentEvent;
input_text.addEventListener(ComponentEvent.ENTER, readInput);
input_text.addEventListener(Event.CHANGE, changeHandler);
var clearing:Boolean=false;
function readInput(event:Event):void
input = input_txt.text;
trace(input);
clearing=true;
function changeHandler(event:Event)
if(clearing)
input_text.text="";
clearing=false; -
SoftKeyBoard checking for ENTER key
When I put up the softkeyboard for iOS how can I test when the ENTER key has been pressed using actionscript 3.
Currently I listen for the SoftKeyboardEvent.SOFT_KEYBOARD_DEACTIVATE to call a function but would rather do it using the ENTER key (go, search etc return key labelled key).
Please note I am using Flash Pro not Flex.Do you really want to recheck it in a loop? It seems to me that it would be easier to create a separate thread that reads System.in, blocks on it, and then issues an event when it gets something.
-
Making ENTER key act as a TAB key.
I have a version problem that I could not solve. My goal is using ENTER key as TAB key.
In java version 1.3.X my code is working properly.It is like the code below
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_ENTER) e.setKeyCode(KeyEvent.VK_TAB);
In java version 1.4.X it is not working. Can anybody help me please?Thanks a lot. It is really a good document that everybody should read.
I have copied some portion of it for others searching about this topic.It is below.
KeyListeners installed on Components will no longer see KeyEvents that map to focus traversal operations. Previously, AWT Components saw these events and had an opportunity to consume them before the AWT initiated focus traversal. Code that requires this functionality should instead disable focus traversal keys on its Components and handle focus traversal itself. Alternately, the code can use an AWTEventListener or KeyEventDispatcher to pre-listen to all KeyEvents. -
Remove the key listener from JTable problem please help
Hi
I�m trying to remove the key listener from my table, it doesn�t work,
I�m pressing the enter key it still goes to the next row from the table,
hear is my code
KeyListener[] mls = (KeyListener[])(table.getListeners(KeyListener.class));
for(int i = 0; i < mls.length; i++ )
table.removeKeyListener(mls);
Please help thanksHm ...
that should indeed remove all the KeyListeners from your table - the question is only, when does this happen?- Where in your code do you remove the KeyListeners?- I am quite sure, you remove them successfully, but after your have removed them, one or more KeyListeners are added to the table.
greetings Marsian -
Please Try to Help Me on this ............
I Have a Screen where I need to traverse focus (it has textfields, combo boxes and buttons) when I press the Enter Key (like Tab).
I used a Key listener and was able to do it (to a certain point)
The code I have written is below ..
Now The problem is when the focus sets on a JComboBox, it wont go further (tab works). I know that the enter key in a JComboBox is used to select a item.
So what I need is first to be able to select an item using the enter key and when press enter key again, the focus must go to the next component.
Is there a way to do it ???
(JCheckBox and JButton has similar problems)
SymKey aSymKey = new SymKey();
textfield1.addKeyListener(aSymKey);
textfield2.addKeyListener(aSymKey);
combobox1.addKeyListener(aSymKey);
combobox2.addKeyListener(aSymKey);
checkbox1.addKeyListener(aSymKey);
textfield3.addKeyListener(aSymKey);
button1.addKeyListener(aSymKey);
class SymKey extends KeyAdapter {
public void keyPressed(KeyEvent e){
if (e.getKeyCode() == e.VK_ENTER) {
if (e.isShiftDown())
FocusManager.getCurrentManager().focusPreviousComponent((JComponent)e.getSource());
else
FocusManager.getCurrentManager().focusNextComponent((JComponent)e.getSource());Hi,
You need to implement the focusmanager, and set currentfocusmanager with your focusmanger.Then it works out.Because Jcombobox is editable the keyevent of the combobox executes .
Hope it helps.
venkat -
Hello
I have a problem with JMenuKeyListener, I have JTextField when I writing there is a popup appear then I have to choose from the Popup Menu by ENTER key, but it dose not work... any Idea?
Note: when you enter text on the JTextField start with 'i' ... :)
this is the Code:
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class TestJMenuItemLKeyistener extends JFrame implements KeyListener
private static final long serialVersionUID = 10000L;
private JButton exitButton = new JButton();
private JLabel resultLabel = new JLabel();
private JLabel searchInPopupLabel = new JLabel();
private JMenuItem item1 = new JMenuItem("item1");
private JMenuItem item2 = new JMenuItem("item2");
private JMenuItem item3 = new JMenuItem("item3");
private JPopupMenu popup = new JPopupMenu();
private JTextField textField = new JTextField();
* Launch the application
* @param args
public static void main(String args[])
try
TestJMenuItemLKeyistener frame = new TestJMenuItemLKeyistener();
frame.setVisible(true);
catch (Exception e)
e.printStackTrace();
* Create
public TestJMenuItemLKeyistener()
super();
try
createPopup();
jbInit();
catch (Throwable e)
e.printStackTrace();
private void createPopup()
popup.setPopupSize(new Dimension(200,120));
popup.setPreferredSize(new Dimension(200,120));
popup.add(item1);
popup.add(item2);
popup.add(item3);
private void jbInit() throws Exception
textField.setBounds(10, 10, 200, 40);
textField.addKeyListener(this);
resultLabel.setHorizontalTextPosition(SwingConstants.CENTER);
resultLabel.setHorizontalAlignment(SwingConstants.CENTER);
resultLabel.setText("Result");
resultLabel.setBounds(10, 56, 200, 40);
exitButton.setBounds(10, 216, 200, 40);
exitButton.setText("Exit");
exitButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
System.exit(0);
item1.addKeyListener(this);
item2.addKeyListener(this);
item3.addKeyListener(this);
this.setSize(400, 300);
this.setTitle("Test JMenuItem Listener");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().setLayout(null);
this.getContentPane().add(textField);
this.getContentPane().add(resultLabel);
this.getContentPane().add(exitButton);
this.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width-this.getWidth()>>1,
Toolkit.getDefaultToolkit().getScreenSize().height-this.getHeight()>>1);
getContentPane().add(searchInPopupLabel);
searchInPopupLabel.setForeground(Color.RED);
searchInPopupLabel.setHorizontalAlignment(SwingConstants.CENTER);
searchInPopupLabel.setText("Search in Popup");
searchInPopupLabel.setBounds(216, 10, 166, 40);
public void keyPressed(KeyEvent e)
public void keyReleased(KeyEvent e)
if(e.getKeyCode() != KeyEvent.VK_DOWN && e.getKeyCode() != KeyEvent.VK_ENTER)
createPopup();
popup.setVisible(false);
textField.requestFocus(true);
String text = textField.getText();
Component[] its = popup.getComponents();
for(Component it: its)
if(!((JMenuItem)it).getText().startsWith(text))
popup.remove(((JMenuItem)it));
popup.setPreferredSize(new Dimension(textField.getSize().width, popup.getComponents().length*40));
popup.show(textField, 0, textField.getHeight());
textField.requestFocus(true);
if(e.getKeyCode() == KeyEvent.VK_ENTER)
if(e.getSource() instanceof JMenuItem)
resultLabel.setText(((JMenuItem)e.getSource()).getText());
public void keyTyped(KeyEvent e)First of all you should be adding ActionListeners to the MenuItem, not KeyListeners, to handle the selection of a menu item.
Also, focus should remain on the popup:
popup.show(textField, 0, textField.getHeight());
// textField.requestFocus(true); -
On stage i have a button, TextInput and a TextArea component. I want the user to add some content in the TextInput field and when Enter is clicked on the Keyboard the content will be transferred and displayed in the TextArea. How do i do this? I know the keyCode == Keyboard.ENTER is to recognize when enter is pressed but to do this is more complicated.
Thank YouAssign a listener for a KeyboardEvent and if the event indicates the Enter key was used, write the text to the textarea.
stage.addEventListener(KeyboardEvent.KEY_UP, writeText);
function writeText(event:KeyboardEvent):void {
if(event.keyCode == Keyboard.ENTER){
// write the text to the textarea
Maybe you are looking for
-
Looking for Video call soluation
Dears ; Good evening I want to know if there is a solution for video calls between 2 citys via VPN link if there is virtual solution or programs Thanks all and sorry for bad English Posted by WebUser Mohammadrios Hakawaty from Cisco Support Community
-
How to generate passwordDigest and nonce in VBA excel ?
Hi All, I need to consumme a webservice in VBA Excel. I need to generate a passwordDigest in order to fill this XML: <SOAP-ENV:Header>X-WSSE: UsernameToken Username="MYUSERNAME", PasswordDigest="???PasswordDigest???", Nonce="???Nonce???", Created="20
-
Satellite L300-1AS - Specification of PC/Express card slot
I have 4 week old L300-1AS. My quest is I hope simple? what is the corect card spec for this laptop? the slot is 54 wide `L` shaped I`ve been told this will take a 34 or 54 card Type ?. I`ve asked Toshiba UK technicians and am very surprised at there
-
NB305-N410BN-G = FN+F8 can't activate 3G / but FN+F8 can activate WIFI
Hi everybody, got also a problem with the Toshiba FN F8 switch under Windows 7 Starter x86 (32Bit). I can switch on and off the transmission of my built in WIFI but not my built in 3G mobile broadband (Sierra Wireless Gobi 2000) anymore. It worked fi
-
Advice about my mini's 24" display
I have a Mac mini Core i7 2.6 (Late 2012), which I love. But my 24" HP ZR2440w monitor has started flickering -- occasional blinking rectangles on different parts of the screen that seem to correspond to disk activity. I've never had monitor trouble