Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » KeyEvent inside Eclipse/WindowBuilder doesn't work(Windowbuilder eclipse Java KeyEvent)
KeyEvent inside Eclipse/WindowBuilder doesn't work [message #995601] Sun, 30 December 2012 16:24 Go to next message
Jesus Gregorio is currently offline Jesus GregorioFriend
Messages: 3
Registered: December 2012
Junior Member
I'm developing a GUI using windowBuilder and Eclipse. I try to use a keyEvent that it shows the key that you push in a window. When I run the program the console shows "Need to specify an input file!".

When I push "Quickly test/preview...." button inside Eclipse/WindowBuilder I can see the window but it doesn't work (if I push a button it doesn't show anything). The code is this one (it's a example I found in a book so I don't know what's the problem):

public class KeyChecker extends JFrame {
JLabel keyLabel = new JLabel("Presiona cualquier tecla");

public KeyChecker() {
super("Presiona cualquier tecla");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 300);
getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
KeyMonitor monitor = new KeyMonitor(this);
getContentPane().setFocusable(true);
getContentPane().addKeyListener(monitor);
getContentPane().add(keyLabel);
setVisible(true);
}
public static void main(String[] args){
new KeyChecker();
}

}
And the KeyMonitor code:

class KeyMonitor extends KeyAdapter{
KeyChecker display;

KeyMonitor(KeyChecker display){
this.display = display;
}

public void keyTyped(KeyEvent evt){
display.keyLabel.setText(" " + evt.getKeyChar());
display.repaint();
}
}

I've run the code in other computers and it works so... Can you tell me a posible solution? Where is the problem?
Re: KeyEvent inside Eclipse/WindowBuilder doesn't work [message #995705 is a reply to message #995601] Sun, 30 December 2012 23:22 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
Quick test/preview does not enable any event handlers. That mode is solely for testing the visual and resizing behavior. You need to run the actual code, if you want to test any event handlers.
Re: KeyEvent inside Eclipse/WindowBuilder doesn't work [message #996598 is a reply to message #995705] Wed, 02 January 2013 13:43 Go to previous messageGo to next message
Jesus Gregorio is currently offline Jesus GregorioFriend
Messages: 3
Registered: December 2012
Junior Member
Thanks for the answer. I'm learning... Anyway the problem wasn't fixed. I think the problem could be the instalation cause I cannot understand why the message "Need to specify an input file!" appears. I've installed eclipse (juno), jre7 and sdk7. What can I do?
Re: KeyEvent inside Eclipse/WindowBuilder doesn't work [message #996615 is a reply to message #996598] Wed, 02 January 2013 14:32 Go to previous message
Jesus Gregorio is currently offline Jesus GregorioFriend
Messages: 3
Registered: December 2012
Junior Member
OK. Finally I solved it... Sorry but I'm stupid... I didn't push the right buttom but the run buttom in the toolbar. Sorry for making you lost time.
Previous Topic:Integrating windowbuilder JFrame into existing code
Next Topic:Custom composite with GridLayout
Goto Forum:
  


Current Time: Fri Mar 29 13:57:29 GMT 2024

Powered by FUDForum. Page generated in 0.08297 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top