Perform -> key press Event on GUI programmatically
-
How can I perform arrow key event for a GUI in my Java Program? Thanks!
-
Use a
KeyListener
[^].Use the best guess
+5 - This is how to get this done[^]
regards Torsten When I'm not working
-
+5 - This is how to get this done[^]
regards Torsten When I'm not working
-
Thanks, all I did was go to the 'K' section in the documentation index. :-\
Use the best guess
Thanks for your suggestions.. My problem is I want to change the item in a Jlist Programmatically. That's why I wanted to use this but Robot(AWT key Press Event)not working. My code is:
listener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
Object o = imageList.getSelectedValue();
if (o instanceof BufferedImage) {
imageView.setIcon(new ImageIcon((BufferedImage)o));}
}
}
imageList.addListSelectionListener(listener);Well the code is working fine but I want to change the next image using a button or something else How can I do this? Please help me in this?
-
Thanks for your suggestions.. My problem is I want to change the item in a Jlist Programmatically. That's why I wanted to use this but Robot(AWT key Press Event)not working. My code is:
listener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
Object o = imageList.getSelectedValue();
if (o instanceof BufferedImage) {
imageView.setIcon(new ImageIcon((BufferedImage)o));}
}
}
imageList.addListSelectionListener(listener);Well the code is working fine but I want to change the next image using a button or something else How can I do this? Please help me in this?
-
Thanks for your suggestions.. My problem is I want to change the item in a Jlist Programmatically. That's why I wanted to use this but Robot(AWT key Press Event)not working. My code is:
listener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
Object o = imageList.getSelectedValue();
if (o instanceof BufferedImage) {
imageView.setIcon(new ImageIcon((BufferedImage)o));}
}
}
imageList.addListSelectionListener(listener);Well the code is working fine but I want to change the next image using a button or something else How can I do this? Please help me in this?
As "Rechard" suggest, add
KeyListener
to yourimageList
and put your logic on KeyPress event to move the next item on the list on up/down arrow key.Regards Shubhashish
-
Thanks for your suggestions.. My problem is I want to change the item in a Jlist Programmatically. That's why I wanted to use this but Robot(AWT key Press Event)not working. My code is:
listener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
Object o = imageList.getSelectedValue();
if (o instanceof BufferedImage) {
imageView.setIcon(new ImageIcon((BufferedImage)o));}
}
}
imageList.addListSelectionListener(listener);Well the code is working fine but I want to change the next image using a button or something else How can I do this? Please help me in this?
Read the tutorial. and maybe make a little "Area51"-project where you try and test things aside from normal coding.
regards Torsten When I'm not working
-
Read the tutorial. and maybe make a little "Area51"-project where you try and test things aside from normal coding.
regards Torsten When I'm not working
Thanks for your suggestions!!! If I'm not concerning in my project then the main task of mine is to change the item in a list on an event(Button or String Pass). ...I can do it on press of right key so I thought to read the right key programmatically. I think you can understand what I want to say.. Thanks!
-
Thanks for your suggestions!!! If I'm not concerning in my project then the main task of mine is to change the item in a list on an event(Button or String Pass). ...I can do it on press of right key so I thought to read the right key programmatically. I think you can understand what I want to say.. Thanks!
-
How can I perform arrow key event for a GUI in my Java Program? Thanks!
KeyListener + passing the focus properly:
@Override
public void keyTyped(KeyEvent ke) {
if(ke.getKeyChar() == KeyEvent.VK_LEFT){
//do something
}else if(ke.getKeyChar() == KeyEvent.VK_RIGHT){
//do something else
}
}@Override
public void keyPressed(KeyEvent e) {
keyTyped(e);
}also by input mapping:
private void inputMap(){
this.getInputMap().put(KeyStroke.getKeyStroke( KeyEvent.VK\_LEFT, 0), "left"); this.getActionMap().put("left", new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) { //do something } }); }