Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextField behaviour when gaining focus

 
Xose Ramos
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I would like to post a question concerning the behaviour of JTextField when it gains focus. I believe it is a kind of bug in the implementation, but all the research I made on the topic has not given me any further information.
Everything started because of a requirement: The text fields in our applications should select the contents when they get the focus. (Easy to see, when a field gets the focus, text should appear with a green background).
This seemed to be so easy because this is the default behaviour of the Windows Look and Feel. This is what is said in the WindowsTextFieldUI class:
/**
* Provides the Windows look and feel for a text field. This
* is basically the following customizations to the default
* look-and-feel.
*

    *
  • The border is beveled (using the standard control color).
    *
  • The background is white by default.
    *
  • The highlight color is a dark color, blue by default.
    *
  • The foreground color is high contrast in the selected
    * area, white by default. The unselected foreground is black.
    *
  • The cursor blinks at about 1/2 second intervals.
    *
  • The entire value is selected when focus is gained.
    *
  • Shift-left-arrow and shift-right-arrow extend selection
    *
  • Cntrl-left-arrow and cntrl-right-arrow act like home and
    * end respectively.
    *

  • */
    Unfortunately:
    I have found out in Sun JVM this was not working at all (JVM 1.2.2, JVM 1.3.1, JVM 1.4b). But on a IBM JVM (JVM 1.2.2) it worked fine.
    This was somehow confusing me completely. An anouced behaviour is later not working in the implementation. Why?
    I solved the problem by simply calling the WindowsTextFieldUI specifically and assigning it to the JTextFields. I did not rewrote any code, I just simply made sure the class was being used.
    Does anybody knows about this problem? Is that a problem with the Windows Look and Feel? Should I notify Sun about this?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic