JTextField ActionListener
Dear forum,
I am currently working on a code that will allow an employee to add an integer value to one of many text fields.
I have a list of text fields that indicate times (5 AM - 5 PM) i have set them to not editable. How ever i would like to have a new frame pop up when a user clicks on the JTextField... at the moment if you add a normal actionlistener such as the button ones it will only execute the code if the enter key is pressed.
And no i do not wish to replace them with buttons as the design will look terrible if so. So in the short run i need to know how to execute data if the JTextField is clicked and not the enter key pressed.
Re: JTextField ActionListener
I'm curious how to do this as well. I'd like it if you could just auto-update simply because new text was put into the field at all.
Re: JTextField ActionListener
So I checked my book and it looks like you can do a KeyListener for the frame..
Code :
import java.awt.event.*;
addKeyListener( this );
public void keyPressed(KeyEvent event)
{
line1 =String.Format("%s", KeyEvent.getKeyText(event.getKeyCode()));
setLines2and3(event);
}
also event.getKeyChar()
yup just a bunch of random code I know, but maybe you get the idea. I'll try it more in the morning.
Re: JTextField ActionListener
im pretty sure for the auto update it wouldnt be actionlistener. u'd have to implement keylistener and give that a try
Re: JTextField ActionListener
Wouldn't that work for what your trying to do?
Re: JTextField ActionListener
nah i need the code to execute if somebody clicks on the text field. not presses a key
Re: JTextField ActionListener
well with a mouse listener you can't use event.isMetaDown() or event.isAltDown()? or whatever to tell if they are clicking on the field? or even use cordinates to make sure if they click in the right spot? You don't need buttons for that.
Re: JTextField ActionListener
i think im going to add a new button at the bottom to add the schedualed data.. I believe it will be much easier for the moment:P cheers for trying though.
Re: JTextField ActionListener
Quote:
How ever i would like to have a new frame pop up when a user clicks on the JTextField
A MouseListener would allow you to listen for any sort of mouse click and act accordingly.
How to Write a Mouse Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)
Re: JTextField ActionListener
thanks mate that seemed to work :D " why oh why didnt i think of that @! lol "