Submitted On 22-FEB-1999
flaggg
Forgot to mention in my previous note:
Focus works just as expected in JDK1.1.6.
Submitted On 22-FEB-1999
flaggg
I am experiencing the same problem.
Here is some very simple sample code that can demonstrate the issue:
import javax.swing.*;
//
//
// Main
//
//
public class Main {
public static void main(String[] args) {
JWindow container = new JWindow();
container.setSize(640, 480);
container.getContentPane().setLayout(null);
JTextField t1 = new JTextField("name");
t1.setBounds(100, 100, 100, 25);
container.getContentPane().add(t1);
JTextField t2 = new JTextField("password");
t2.setBounds(100, 200, 100, 25);
container.getContentPane().add(t2);
container.setVisible(true);
}
}
When you click on either of the textfields no cursor appears, but the textfield
will receive keyboard events.
I can reproduce this with JDK1.2 and JDK1.1.7b
Please fix this ASAP. We would really like to be able to take advantage of 1.2,
but can't if focus doesn't transfer properly within a JWindow.
Submitted On 26-MAY-1999
smithaj
We have found a reasonable work around to this:
Extend JTextField and override requestFocus and grabFocus as follows...
public void requestFocus()
{
super.requestFocus();
if (fJTextField != null)
fJTextField.getCaret().setVisible(false);
fJTextField = this;
getCaret().setVisible(true);
}
public void grabFocus()
{
super.grabFocus();
if (fJTextField != null)
fJTextField.getCaret().setVisible(false);
fJTextField = this;
getCaret().setVisible(true);
}
fJTextField in this case is a class member in a containing class (our extension
is an inner class), basically something to track which component has focus.
Hope this helps people until a proper fix arrives.
Submitted On 22-JUN-1999
chrisburkey
This work around is not a good one. Because the focus
events are not run. All you this does is turn on the caret.
Submitted On 07-JUL-1999
chrisburkey
This bug is important. This focus problem in JWindows means that
You can't create a product such as WinAmp or any borderless popup
with data entry on them.
It looks like a top 25 bug!
Submitted On 11-JUL-1999
sequel
I encourage everyone that needs this bug fixed to <strong>cast your vote
on Bug Id 4150988</strong>.
SUN, I hope that before anyone tries to rewrite code to get around the problem
you fix the REAL bug in the AWT.
There are now three bug reports for the same problem. Bug Id 4128659, 4150988,
and 4150988.
Submitted On 16-JUL-1999
torelli
I have found other strange behaviors of JWindow.
If you add a FocusListener on a JWindow, the
listener don't receive any FocusEvent, but if you
add the FocusLister on a component in the JWindow
too, the listener receive the event on the
JWindow!
If you execute JWindow.requestFocus(), it happens
this sequence of events on JWindow:
1)permanent focus gained
2)permanent focus lost
3)permanent focus gained
Why I get three events instead of only one event
(focus gained)?
Submitted On 31-JUL-1999
rootss
I run into the same problem and I saw this workaround:
http://www.codeguru.com/java/articles/446.shtml
It works great for me.
Submitted On 06-AUG-1999
chrisburkey
That work around does not solve this problem. Because if there is more than one
JTextField you can't even tab between them. In fact, even if you use your mouse
to click inside one it still does not take focus!
Submitted On 06-OCT-1999
chrisburkey
In reading the review from 1999-02-09 it indicates that all JWindows need to
have an owning JFrame. Then how can we use a JWindow as a top level container?
For example, I need to create an initial login screen with no Frame.
Submitted On 23-NOV-1999
Roland1753
I have the same problem as chris above.It would be nice if JWindow were a top
level component.
Submitted On 24-NOV-1999
JROSEN
I think the main problem of this bug is that the VM doesn't send the message
"WindowEvent.WINDOW_ACTIVATED" to JWindow. So JWindow doesn't
"know" that it is active and it cannot handle the focus correctly.
I have tried out this workaround and it worked fine in my application (insert
these lines into the constructor of the JWindow-Class):
setVisible(true); // make it visible first
requestFocus(); // the window is active now
dispatchEvent(new WindowEvent(
this, WindowEvent.WINDOW_ACTIVATED));
Submitted On 05-FEB-2000
DanielMichalik
In jdk1.3 RC1 still persists. I cant place textfield into JWindow
Submitted On 17-FEB-2000
bst5qi
"because the Window never actually should have focus --
instead, the Frame or Dialog that owns it should get the key
events and dispatch them to the Window when appropriate"
This seems the idea/spec of Window activation aso.
I don't agree; why should a Window behave differently from
Frame or Dialog concerning activation, focussing aso!!!???
On Windows at least if you click on a Window with the mouse
the parent Frame's title bar is deactivated (see background color),
so my intuition says that the Window should get activated.
But in the current implementation neither Window or Frame
is activated which is surely an invalid AWT state.
Submitted On 29-FEB-2000
fordmi
As of this writing, bug 4199374 has 178 votes, 4254005 has 27, 4186928 has 39, and who knows how many other
bugs are duplicates! This makes it the 3rd most reqested bug fix.
The cleanest and easiest workaround is to subclass JWindow and add the following code in the constructor. It took
me days to figure this out!
addFocusListener(new FocusListener() {
public void focusLost(FocusEvent e) { }
public void focusGained(FocusEvent e) {
dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_ACTIVATED));
}
});
In bug #4186928, jhtpenttech arrived at the same conclusion and gives a detailed explaination why.
Submitted On 09-MAY-2000
chrisburkey
According to this press release: http://java.sun.com/products/jdk/1.2/CHANGES-1.2.2_005.html#5
this bug is fixed. Then why is it still labeled "In progress, bug"?
Submitted On 12-SEP-2000
a_petkov
:))))
Hi all i don't know if the bug is fixed but here is my solution.
You all call JWindows method setVisible(true)
this metod is supposed to replace the metod show()
but some how he could not fully replace it so
you shold when use JWindow's method setVisible(true) to call after him show()
here is an example :
public class Blq {
public JWindow window;
...
...
window.setVisible(true);
window.show();
...
...
}
after this when you call requestFocus() method of some of window's componets it wil work properly
Submitted On 19-APR-2001
cornwellsb
This works
private void setTextFocus(){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
txtBox.requestFocus();
}
});
}
Submitted On 18-MAY-2001
langles
Apparently this bug was fixed ... for a while. In the
release notes for the newly released JDK1.3.1,
http://java.sun.com/j2se/1.3/relnotes.html#awt
Bug 4199374 concerns a focus management problem with JWindow
objects. In particular, this bug prevents
Component.requestFocus() from giving focus to components in
a JWindow. This bug was fixed in update releases J2SDK
1.2.2_05 and J2SDK 1.3.0_02. However, it is not fixed in
J2SDK 1.3.1.
Submitted On 02-NOV-2001
krishnars
for me... i wanted to use textfiled.requestFocus(); in
focusLost(Focusevent e) method if that textfield validation
is wrong. no way it is not reseting to the sameTextfield on
jdk1.2.2.
But i got solution...from cornwell...thanks
It works with....calling this method in FocusLost method
private void setTextFocus(){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
txtBox.requestFocus();
}
});
}
It is working fine right now on 1.2.2 also.
Is there any problems in future ? and is there any better
work-arrounds?
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|