Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JPopup -> strange focus behaviour  RSS feed

 
slacker
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to code a JTable that would react as follows: clicking a table header pops up a little filter component (a textfield + a combobox) under this header using a JPopup.Then, I'd like it to disappear when loosing the focus.
So I added a FocusListener on the component embedded in the popup (it basically outputs the focus events and make the popup disappear when having lost the focus).
And I tested it... I make it appear by clicking a header and when I click on another component (losing the focus) I'm prompted with the event and the popup disappears.
Everything seems alright but it appears that once one of the popup components has been clicked. No matter what I do, the popup component stops sending focus lost/gained events.
any idea?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
slacker,

Please re-register with a user name that follows the JavaRanch User Name Guidelines. Your user name is required to be in the form "First Name" + space + "Last Name", and cannot be obviously fake.

It would also really help if you posted the code that you were having a problem with. JPopup doesn't seem to be a standard API class...

-Nate
 
Alex Ku
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I had the same problem but with JTree, focus was messing up once there a popup dialog was shown.
It turned out it is a bug Java. I don't know if this is in your case. You can check out this bug report on sun's site.
Focus not handled correctly after two consecutive dialogs
Hope this helps
kawaii
 
vinsil reno
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nate,
First, please excuse me for not having followed javaranch username policy (I must say I didn't know of). Here i'm back with a correct register name.
As for the JPopup class, you can forget the J in front of it (i can't help adding a J before a component name ) , it's just a standard javax.swing.Popup. By the way I use jdk 1.4.
I hope it helps you figuring the problem but if you still need the code (it's a bit long), just ask me, i'll post it. Thanks.
Kawaii,
Many thanks for the bug report url, i just can't figure if your bug and the behaviour i experience are related, but i'm gonna try the exposed workaround. It could be another one as the bug you got is supposed to be fixed in Merlin which I use... Anyway thx again
vinsil
[ February 28, 2002: Message edited by: vinsil reno ]
 
vinsil reno
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've found out that this problem is similar to
this bug and this one in the bug parade.
The workaround is to instanciate a Frame and provide it as a container to the PopupFactory getPopup method.

I've tested it and it works fine.
The problem is that I must provide a new and *visible* Frame... quite annoying... i've tried to use the current window but it fails.
How could I avoid this Frame to be visible?
Is there another workaround that would solve this problem?
[ March 01, 2002: Message edited by: vinsil reno ]
 
Alex Ku
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
So, that's exactly the same problem I had before.
But in my case, it was a dialog, not a popup. One
of the workaround they suggested is using a frame
also, attached the dialog to this new "visible"
frame,but make this new frame smaller enough to
be hidden by the dialog. So, the user won't see
this new frame.
The second workaround is using another thread to launch the dialog, using SwingUtilities.invokeLater and invokeAndWait.
So, you could hide the frame behind the popup, or
using a new thread(bad thing for this one is there
is some delay)
kawaii
 
vinsil reno
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Kawaii, I've tried the invokeAndWait workaround but it doesn't seem to work in my special case.
It's a pity coz i can't hide the frame (even with a (0, 0) size) under my tiny popup...
Anyway, thx a lot for yr help.
 
Alex Ku
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
how about setLocation(-100,-100)? makes it off the screen?
kawaii
 
vinsil reno
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kawaii,
Simple and efficient!
How come I didn't think about it?
Once again, thanks a lot for your help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!