KeyTyped Event: funny behaviour

This should be a very simple question... but I am stuck with it.
I want to implement the usual feature of enabling a button only if a text field is not empty. I suppose you all have seen this before.
I am catching the KeyTyped event and in the event handler I am checking for the length of the text. This is the code inside the handler:
String txt=myTextField.getText();
myButton.setEnabled(txt.length()>0);
So yes, it works, but with a funny behaviour: the button is enabled only after the second keystroke, that is, when the length of the text is >=2 and not >0. A quick explanation is that my event handler is being called before the event handler of the textfield itself so at that moment the text is still empty. But when pressing the "backspace" key... it works fine, so the theory is wrong!!
My workaround is to catch the KeyReleased event... but visual effect is not so satisfactory, and anyway, why is this happening?
And what is the "official" way of implementing this trick?
Thanks in advance,
Luis.
(P.S.: I am using a JTextField and a JButton, and have tested this with JDK 1.2 and 1.4 with the same results.)

You'd want to do something like this:
JTextField watchedField = new JTextField();
// construct the action
FieldWatcherAction watcher = new FieldWatcherAction( watchedField );
// make a button with the action
JButton b = new JButton( watcher );
// add a button to a toolbar with the action
jtoolBar.add( watcher );
// etc...
class FieldWatcherAction extends AbstractAction implements DocumentListener
  JTextField  field;
  public FieldWatcherAction( JTextField f )
    super( "", someIcon );
    setEnabled( false );
    field = f;
    field.getDocument().addDocumentListener( this );
  protected void updateState()
    setEnabled( field.getDocument().getLength() > 0 );
  public void insertUpdate( DocumentEvent evt )
    updateState();
  public void removeUpdate( DocumentEvent evt )
    updateState().;
  public void changedUpdate( DocumentEvent evt )
    updateState();
}The action would need to be fleshed out more, obviously. You'd probably want to add text for a label ( empty string in super call in constructor ), define the icon ( second arg in super call ). You can also set tooltip text and other things. All of this can be changed by editing various properties of the action. Relevant constants would be:
javax.swing.Action.ACCELERATOR_KEY  // key accelerator for JMenuItems
javax.swing.Action.MNEMONIC_KEY // mnemonic key for JMenuItems
javax.swing.Action.NAME // JButton text or JMenuItem text
javax.swing.Action.SHORT_DESCRIPTION // Tooltip text
javax.swing.Action.SMALL_ICON // image icon for JButton, JMenuItem and JToolBar buttons.

Similar Messages

  • KeyTyped events not generated

    I've got a JTextArea. I wanted to allow focus traversal with standard TAB keys, so I provided a KeyListener that consumes TAB events. The problem is, that if I shift-tab to my textArea (it's placed in a JPanel), the first pressed key is ignored.
    After a little investigation it turns out, that for the very first key pressed after the JTextArea has gained focus no keyTyped event is generated - only keyPressed and keyReleased. Why is that? Why does it happen only after shift-tabbing to the JTextArea (tabbing to it does not produce this strange behaviour)?
         textArea.addKeyListener(new KeyAdapter() {
                   @Override
                   public void keyPressed(KeyEvent e) {
                                  if (e.getKeyCode() == KeyEvent.VK_TAB && (e.getModifiers() == 0 || e.getModifiers() == KeyEvent.SHIFT_MASK)) {
                             if (e.getModifiers() == KeyEvent.SHIFT_MASK) {
                                  textArea.transferFocusBackward();
                             } else {
                                  textArea.transferFocus();
                             e.consume();
                   }

    You might have better luck getting a helpful response if you create a Short, Self Contained, Correct (Compilable), Example or SSCCE. This is a small application that you create that is compilable and runnable, and demonstrates your error, but contains no extraneous, unnecessary code that is not associated with your problem. To see more about this and how to create this, please look at this link:
    http://homepage1.nifty.com/algafield/sscce.html
    Remember, this code must be compilable and runnable.
    I tried to create one of my own but could not reproduce your problem:
    import java.awt.GridLayout;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    class SwingFoo1 extends JPanel
        JTextArea[] textAreas = new JTextArea[3];
        SwingFoo1()
            setLayout(new GridLayout(0, 1));
            for (int i = 0; i < textAreas.length; i++)
                JPanel panel = new JPanel();
                JTextArea textArea = new JTextArea(5, 60);
                JScrollPane scrollpane = new JScrollPane(textArea);
                panel.add(scrollpane);
                add(panel);
                textAreas[i] = textArea;
                final int iFinal = i;
                textArea.addKeyListener(new KeyAdapter()
                    @Override
                    public void keyPressed(KeyEvent e)
                        if (e.getKeyCode() == KeyEvent.VK_TAB
                            && (e.getModifiers() == 0 || e.getModifiers() == KeyEvent.SHIFT_MASK))
                            if (e.getModifiers() == KeyEvent.SHIFT_MASK)
                                textAreas[iFinal].transferFocusBackward();
                            else
                                textAreas[iFinal].transferFocus();
                            e.consume();
            JPanel buttonPanel = new JPanel();
            JButton fooButton = new JButton("Foo");
            buttonPanel.add(fooButton);
            add(buttonPanel);
        private static void createAndShowGUI()
            JFrame frame = new JFrame("SwingFoo1 Application");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(new SwingFoo1());
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            javax.swing.SwingUtilities.invokeLater(new Runnable()
                public void run()
                    createAndShowGUI();
    }

  • Please help me in KeyTyped Event in Swing

    hi,
    goodmorning
    In my project I have a Frame.on that Frame I put a JDesktopPane which contains one JInternalFrame.I wrote coding in KeyTyped event and mouse clicked event of all i,e in my JFrame,JDeskotpPane and JInternalFrame.
    No problem in all my mouse clicked events.When I click the mouse in my objects the corresponding actions done.
    But when I typed keys in my JFrame only works well.When I type keys in my jDesktopPane or JinternalFrames nothing happen.will you please explain me what is the reason and the solution.

    Well, I am not a swing guru, so my answer may not be correct. My assumption is that you have to add the KeyListener not just for your Frame but for all the components inside the Frame.
    For that you have to add a container listener so that when you add new components to your Frame, you might as well add the KeyListener for that. I will give you a link, so that it may explain you better than what I did, because I am a newbie too... :)
    Here's the link: http://java.sun.com/docs/books/tutorial/uiswing/events/containerlistener.html
    When a new component is added, add the key listener for that component, and check whether the newly added component is a container, if it is a container, then add the container listener to that component... All these things must be done in the componentAdded(ContainerEvent e) method.
    In my project I have a Frame.on that Frame I put a
    JDesktopPane which contains one JInternalFrame.I
    wrote coding in KeyTyped event and mouse clicked
    event of all i,e in my JFrame,JDeskotpPane and
    JInternalFrame.
    No problem in all my mouse clicked events.When I
    click the mouse in my objects the corresponding
    actions done.
    But when I typed keys in my JFrame only works
    well.When I type keys in my jDesktopPane or
    JinternalFrames nothing happen.will you please
    explain me what is the reason and the solution.

  • Handling keyTyped events in JTable for TAB key

    In my app, I have a JTable. Some columns are non-editable.
    I have attached a keyListener to the table and have overridden keyTyped() and keyReleased() methods.
    In keyReleased(), I do something depending on the key code. For example: if its the VK_DELETE, I delete the row. If its some other user configured key, then I show a popup dialog where the user can enter some data, etc...
    In keyTyped(), I first check if the column is one of the specific columns. Then I get the keyChar. After this, I show a dialog and pre-populate a JTextField on this dialog with that keyChar.
    My issue is that 'TAB' key events arrive in keyTyped() and not in keyReleased(). As a result, the dialog is shown and the tab takes place inside the JTextfield which is incorrect.
    I would like to ignore TAB keyTyped events. When I look up the keyCode in keyTyped() method, it is 0. So there is no way for me to tell what key was typed.
    How can I ignore TAB events in my keyTyped() method?
    thx

    I now do the following to determine if TAB key has been typed
    public void keyTyped(KeyEvent e) {
    char c = e.getKeyChar();
    if (c == KeyEvent.VK_TAB) {
    Is this correct ?
    Edited by: tsc on Sep 28, 2007 12:40 PM

  • Design for mirroring keytyped events for a shared editor

    Hi there,
    Can anyone suggest a layout for an algorithm which will allow a shared editor to handle keytyped events and have that mirrored in the listening client?
    So far the received packets get added to a JEditorPane by a setText() call, but this is useless as it overwrites anything in the JEditorPane.. As every KeyTyped event is fired the packet gets sent to another client that needs to append them to the JEditorPane. But I also need to consider the Caret position, deleted text, tab and space (everything under the sun that could happen when someone is editing text in the JEditorPane).
    Has anyone got any suggestions as to how to correctly tackle this problem..
    Thanks : -)
    Adrian

    It may be possible but I still wouldn't do it that way. Mainly because key events aren't sufficient to synchronize two documents. It's possible to change a document without a keyevent occurring -- for example if you press Ctrl-V on many computers, it will paste the contents of the clipboard into the document. I don't know if you get a key event in this case, but even if you do it doesn't tell you enough to synchronize the remote document properly.

  • Pie Chart - Funny Behaviour

    I have a funny problem since this evening. I have this pie chart which I haven't touched since months. Suddenly it shows the following behaviour:
    1. IE7 and FF 1.07 and lower do not show the graph but only the legend
    2. FF 1.5 brings the following error message:
    XML-Verarbeitungsfehler: Nicht übereinstimmendes Tag. Erwartet: </svg>.
    Adresse: http://pd2.synventive.de:7777/pls/htmldb/f?p=100:1:3744672020718222378:FLOW_SVG_CHART_R257606147512709117_de
    Zeile Nr. 27, Spalte 4745:.legenditem rect{stroke:#000000;stroke-width:0.5px;}</style><script xlink:href="/i/javascript/svg_js_includes/svg_common/oracle.svgInit.js"/><script ......
    and a lot of code following.
    Any ideas what could be the reason?
    Denes Kubicek

    This is quite strange. I just increased the width of the chart and everything works now as it did before.
    Denes Kubicek

  • TextAreaControl and keyTyped event not working

    I tried to use the keyTyped in a TextAreaControl but the event never fired.
    If I move the addKeyListener to its JTextArea it works.
    Is it a bug or I didn't understand something?
    TIA
    Tullio

    repost

  • Funny Behaviour (scrollpane and jbutton tricking me)

    Hi,
    I'm close to freaking out. I'm building a GUI that acts as kind of data base editor. There is a combobox to select a table, a scrollpane for viewing and thre buttons to add/remov/edit rows. My test data comes from a Properties object and is transferred into a TableModel in order to create and display the table.
    I pick a table from the comobox and the the table is displayed and the buttons are enabled. As soon as the mouse leaves the scrollpane and enters it or one of the buttons again the buttons become disabled and the table disappears. Picking the table again shows everything again, apart from leaving the add-Button disabled from time to time.
    There is a method that is called when the user selects no table but the initial "Select a table" item in the combo box. This method is NOT called (there is debug output to indicate this). There is no MouseListener or MouseMotionListener added to any component.
    What is this??? Why are sometimes only 2 buttons enabled instead of all three?
    This is the event handling code
    private void displayCategory(String category){
            // get category data
            Properties data = getTestProps();
            // create table
            ProfileTableModel ptm = new ProfileTableModel(data);
            ptm.addTableModelListener(this);
            // show table
            JTable table = new JTable(ptm);
            table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            ListSelectionModel rowSM = table.getSelectionModel();
            rowSM.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent e) {
                    //Ignore extra messages.
                    if (e.getValueIsAdjusting()) return;
                    ListSelectionModel lsm =
                            (ListSelectionModel)e.getSource();
                    if (lsm.isSelectionEmpty()) {
                        System.err.println("GUI no row selected");
                    } else {
                        int selectedRow = lsm.getMinSelectionIndex();
                        System.err.println("GUI row #" + selectedRow + " selected");
            profilePanel.displayTable(table, true);
        private void clearDisplay(){
            System.err.println("GUI DISPLAY NOTHING");
            profilePanel.displayNothing();
        public void itemStateChanged(ItemEvent e) {
            System.err.println("GUI ITEM STATE CHANGED " + e);
            if (e.getStateChange() == ItemEvent.SELECTED){
                if (e.getItem() instanceof BoxItem){
                    final String cmd = ((BoxItem)e.getItem()).getCommand();
                    (new Thread(new Runnable(){public void run(){displayCategory(cmd);}})).start();
                } else {
                    clearDisplay();
        }This is the GUI code
        protected void displayTable(JTable table, boolean editable){
            addButton.setEnabled(editable);
            removeButton.setEnabled(editable);
            editButton.setEnabled(editable);
            table.setPreferredScrollableViewportSize(new Dimension(400, 330));
            scroll.setViewportView(table);
        protected void displayNothing(){
            System.err.println("GUI display nothing . . . . . . . . . . .");
            scroll.setViewportView(blank);
            addButton.setEnabled(false);
            removeButton.setEnabled(false);
            editButton.setEnabled(false);
        }Cheers,
    Joachim

    There is a method that is called when the user
    selects no table but the initial "Select a table"
    item in the combo box. This method is NOT called
    But this method displayNothing() is the only place where buttons are
    disabled (at least acording to the posted code fragments).
    How can buttons be disabled when this method is not called?
    You see, it's difficult to test your code because it is not a self-contained
    compilable example.
    A short self-contained compilable example often helps you and
    others to discover an otherwise mysterious bug.

  • Funny behaviour of JSpinner

    please help me solving this peculiar problem with jspinner . I got a jspinner , a text box and a button of my frame.i have written code to valdiate the value entered in text field. If an invalid value is entered an error dialog is show. and focus is returned to the textbox.. Now if I enter an invalid value in the text field and click the small buttons in jspinner, the error dialog is displayed and focus is returned back to the textbox but the problem is that the spinner button remains in a pressed condition as a result the number keeps of increasing / decreasing in jspinner (if you click both the buttons , it will increase and decrease at the same time). I am including the code also.
    I have searched through the forums and find that its a problemm with the look and feel. Can any one suggest a simple method to rectify it ??
    thanks in advance
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class focus extends JFrame implements FocusListener {
    JPanel pan1=new JPanel();
    JButton btn1=new JButton("OK");
    JButton btn2=new JButton("Cancel");
    JTextField txt1=new JTextField(10);
    SpinnerCircularNumberModel model=new SpinnerCircularNumberModel(50);
    JSpinner spin=new JSpinner(model);
    focus() {
    getContentPane().setLayout(new FlowLayout());
    getContentPane().add(txt1);
    getContentPane().add(btn1);
    getContentPane().add(btn2);
    getContentPane().add(spin);
    txt1.addFocusListener(this);
    setSize(200,200);
    setVisible(true);
    pack();
    public void focusGained(FocusEvent fe) {
    public void focusLost(FocusEvent fe) {
         try {
              Integer.parseInt(txt1.getText());
         } catch ( NumberFormatException nfe) {
              JOptionPane.showMessageDialog(this, "Invalid value","ERROR", JOptionPane.ERROR_MESSAGE);               
    txt1.requestFocus();
    public static void main(String arg[]) {
    focus f=new focus();
    class SpinnerCircularNumberModel extends SpinnerNumberModel {
    public SpinnerCircularNumberModel(int init) {
    super(init,0,99,1);
    public Object getNextValue() {
    int val = Integer.parseInt(getValue().toString());
    if(val==99)
    return (new Integer(0));
    else
    return (new Integer(++val));
    public Object getPreviousValue() {
    int val = Integer.parseInt(getValue().toString());
    if(val==0)
    return (new Integer(99));
    else
    return (new Integer(--val));

    I used it in the following way:
    class OptEmSpinner extends EmSpinner{
    public OptEmSpinner() {
    public interface RevertListener extends EventListener
         * The value has been Reverted to a the old valid value.
         * @param source is this bean.
         public void valueReverted(Component source);
    public static class OptNumberEditor extends NumberEditor {
         public OptNumberEditor(JSpinner spinner) {
         super(spinner);
         public void propertyChange(PropertyChangeEvent e)
              OptEmSpinner spinner = (OptEmSpinner)getSpinner();
              if (spinner == null) return; // Indicates we aren't installed anywhere.
              Object source = e.getSource();
              String name = e.getPropertyName();
              if ((source instanceof JFormattedTextField) && "value".equals(name))
                   Object lastValue = spinner.getValue();
                   // Try to set the new value
                   try
                        spinner.setValue(getTextField().getValue());
                   catch (IllegalArgumentException iae)
                        // Spinner didn't like new value, reset
                        try
                             ((JFormattedTextField)source).setValue(lastValue);
                        catch (IllegalArgumentException iae2)
                             spinner.fireValueReverted(e);
                             // Still bogus, nothing else we can do, the
                             // SpinnerModel and JFormattedTextField are now out
                             // of sync.
              else
                   spinner.fireValueReverted(e);
    protected JComponent createEditor(SpinnerModel model) {
         if (model instanceof SpinnerNumberModel) return new OptNumberEditor((JSpinner)this);
         return super.createEditor(model);
    private void fireValueReverted(PropertyChangeEvent e)
         Object source = e.getSource();
         String name = e.getPropertyName();
    // JFormattedTextField jft = ((DefaultEditor) getEditor()).getTextField();
         JComponent jft = ((DefaultEditor)getEditor()).getTextField();
         if ((source instanceof JFormattedTextField) && "editValid".equals(name))
              if (!jft.hasFocus()) // ensure lost focus
                   Object[] listeners = listenerList.getListenerList();
                   for (int i = listeners.length - 2; i >= 0; i -= 2)
                        if (listeners[i] == RevertListener.class)
                             ((RevertListener)listeners[i + 1]).valueReverted(jft);
    public void addRevertListener(RevertListener revListener)
         listenerList.add(OptEmSpinner.RevertListener.class, revListener);
    public void removeRevertListener(RevertListener revListener)
         listenerList.remove(OptEmSpinner.RevertListener.class, revListener);
    USED in class:
    public class MyPanel extends JPanel implements OptEmSpinner.RevertListener
    LISTENER IMPLEMENTATION:
    public void valueReverted(Component source)
              Runnable runnable =
                        new Runnable()
                             public void run()
                                  EmOptionPane.showSemiModalMessageDialog(
                                       parent,
                                       sRes.getString("Invalid Value: Old value will be retained."),
                                       sRes.getString("Invalid Input"),
                                       JOptionPane.WARNING_MESSAGE
    //                              dialogShown = false;
                   SwingUtilities.invokeLater(runnable);
    You can modify or pick from this......
    Regards
    Mohit

  • REAL STRANGE & FUNNY BEHAVIOUR OF CREATOR

    HI JSC team,
    REAL STRANGE BEHAVIOUR I have ever seen is, creator lets me to 'undo' the changes EVEN AFTER SAVING ALL THE CHANGES.
    Actually after saving all the changes, the 'undo icon' must be inactive but its not in my creator. I tried restating creator/pc but no use.
    Could you please look in to issue. What might possibly causing this strange behaviour?
    Cheers
    kush

    Hi Kush,
    Creator does allow us to undo things after saving. So does a host of other editors / programs.
    In Creator the undo will happen for only those tasks performed since the project was opened. For example, let us say, three textFields and a button are added to the jsp page. On undo, the components are removed, the last added component being the first one to be removed. If the project is saved, closed and reopened, the undo will not work.
    I hope this helps you in understanding the behaviour.
    Cheers
    Giri :-)
    Creator Team

  • KeyTyped event problem

    Hi, I have a texfield in which I want the users to enter time in the following format: hh:mm:ss
    My problem is, I want the colons to appear automatically when the user is entering hh and mm fields. I tried using the keypressed event but I am not able to make it work very neatly, i mean there is some problem or the other when I try various inputs, try backspace, delete etc.
    Anybody got any inputs?

    Just an opinion: I find it's a better UI if you have three text fields with colons between the two of them, rather than one field for entering the entire string that will automatically populate the colons. It seems klunky to me when text fields enter or reconfigure data while I type.
    Otherwise, follow the advice in the previous post and it should work out well.

  • Transparent taskbar and other funny behaviour

    Since I made a fresh install of SL my taskbar has been acting all funny. Sometimes my logged in user name is only "half" displayed. That is the name is cut right in the middle. These last days my taskbar takes forever to load upon boot and when it does it is transparent.
    Any cache files or something I can delete?
    Regards

    I have a similar issue - using the included Vista Business-version that came with my T61.
    Sometimes, it seems that the welcome/login-window is showing before the finger-print reader is ready to accept the finger, and hence logging in. Sometimes it doesn't work at all, and I have to log in by typing my password.
    This is not consistent either - sometimes it just works right off, sometimes I have to try 4-5-6 times, and sometimes it just plainly refuses to accept the scan (and not as in it's not recognizing it - just doesn't do anything when scanning).
    So, you're not alone
    IT-technician, running my own company in Bergen, Norway
    Thinkpad T61, 8895CTO C2D 2Ghz/4GB/120GB SSD/1400x1050

  • Tomcat and Mozilla funny behaviour

    Hi,
    I have a funny situation going on involving tomcat, mozilla, and internet explorer.
    I am using tomcat 3.3 to serve my pages.
    When viewed through Internet Explorer, everything is fine, and the pages format quite nicely.
    When I view the same pages through Mozilla, it doesn't seem to find the linked stylesheets, and doesn't attempt any formatting at all?!?!
    When I view the same pages through apache, both IE and Mozilla format correctly.
    So, any ideas why Mozilla wouldn't like Tomcat?

    I hate these kind of issues. It happened to me when changing .css contents and then trying to refresh. Mostly due to the unability to refresh contents on pages redirecting to other pages... no time to press the refresh button.
    I know it's a bad solution, but might be a good test and will finally discard a caching issue:
    Copy res.css to rescopy.css and change the link for that page in question.
    I hope it helps!

  • TES 6.0.3 JOB Triggers Events Action behaviours

    please advice how we can showcase following scenario in a customer POC.
    Scenario:
    1. Customer Run  a JOB
    2. JOB has following exit STATUS
    a. JOB exit status
      i. EXIT 0
      ii. EXIT 1
    b. Script OUTPUT
      i.  SELINUX=permissive
      ii. SELINUX=enforcing
      iii. SELINUX=disabled
    3. if EXIT 0  do nothing
    4. if EXIT 1  email to administrator
    5. if SELINUX=permissive  --> email action
    6. if SELINUX=enforcing --> run JOB-a
    7. if SELINUX=disabled --> run JOB-b

    Hi,
    If your job is setup to trak 0 as a normal completion and anythign else other than 0 will be considered as abnormal completion then you may use a job event to look for abnormal completion so to fire off an email action.
    Im not sure if i understood your question regards the SELINUX selections but if you meant that the job output for your script will be one of those selections you've mentioned then if i  were you i would use a global variable to host the job output  and then use variable events to deal with the different outputs/values so to trigger the appropriate job/action.
    Good luck

  • JTextFeild.setEditable funny behaviour

    Hey Guys I hope someone can help me as I'm completely stuck to whether this is a bug or whether I'm just missing something. Given the following code:
    private void setComponentState( int state )
    switch(state)
    case 1:
    btnSearch.setEnabled( true ); //JButton
    btnReplace.setEnabled( false ); //JButton
    txtBarcodeReplc.setEditable( false ); //JTextFeild
    break;
    case 2:
    btnSearch.setEnabled( false ); //JButton
    btnReplace.setEnabled( true ); //JButton
    txtBarcodeReplc.setEditable( true ); //JTextFeild
    break;
    The problem I'm having is that everything works fine until the 3rd or sometimes the 4th time I call this method with a state=2 param. At this point the txtBarcodeReplc control refuses to enable itself. It changes color as it should and when the properties of the control are queried, the control thinks it's enabled, it's just that you cannot type anything or select inside the control. Interestingly enough, if I remove the calls to the other 2 jbutton controls so that the only thing this method does is reset my JTextFeild control, then it works perfectly fine. I'm curerntly using 1.3.1_09.
    Hope someone has some idea's to how to solve this as I'm completely stumped

    Apologies - the problem I was getting at is that it is unsafe to make calls on Swing components from any thread other than the Swing thread. This is unlikely when you are new to Java.
    As for your problem - you can search the bug database. Does http://developer.java.sun.com/developer/bugParade/bugs/4680302.html look like your problem? If so then the latest version looks to be your only option, or try putting the text field in front (in tab order) of the buttons.

Maybe you are looking for