On Jun 30, 2008, at 8:31 PM, email@hidden wrote:
There is an amazingly stupid problem with swing TextField in Mac version
of JVM.
If you try a simple jTextField.setText("Hello") method in Java it works
fine in windows, but in Mac OS it selects/highlights the entire text.
Even if I use:
jTextField.setSelectionStart(0)
jTextField.setSelectionEnd(0)
it continues to select the entire text. However if I put:
jTextField.setSelectionStart(1)
jTextField.setSelectionEnd(2)
it behaves correctly but only selecting the 2nd character. Why is this?!
This was done to match the native "select all on focus" behavior
present in Mac OS X text widgets. If you move focus between textfields
on Mac OS X, you will find that they always select their contents when
gaining focus. In Java, we also attempt to preserve the text field
selection and the caret location if it has been customized by the
user. As pointed out by another developer here, this has been
documented in the release notes for Java on Mac OS X 10.5 Leopard:
http://developer.apple.com/releasenotes/Java/JavaLeopardRN/ResolvedIssues/chapter_3_section_5.html#4890361
Cheers,
Mike Swingler
Java Runtime Engineer
Apple Inc.