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 11:24 Go to previous message
Jesus Gregorio is currently offline Jesus Gregorio
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?
 
Read Message
Read Message
Read Message
Read Message
Previous Topic:Integrating windowbuilder JFrame into existing code
Next Topic:Custom composite with GridLayout
Goto Forum:
  


Current Time: Sun May 19 00:37:41 EDT 2013

Powered by FUDForum. Page generated in 0.01732 seconds