• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with tabbing behind glasspane

 
Patrik Nilsson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a glasspane that I want to intercept all mouse and input events.

I have tried to impments empty listeners like:

addMouseMotionListener(new MouseMotionAdapter()
{
});
addMouseListener(new MouseAdapter()
{
});
addKeyListener(new KeyAdapter()
{
});

To be able to intercept Keyboardevents it's necessary to request focus on the glasspane
addComponentListener(new ComponentAdapter()
{
@Override
public void componentShown(ComponentEvent pE)
{
requestFocusInWindow();
}
});
and this works fine but if I use te Tab Key I can still get to the component behind the glasspane.
I have then used setFocusTraversalKeysEnabled(false); for the glasspane and this works a little bit better but if I select something in a dialog on top of the glasspane I can still tab to the compoent behind the glasspane.

Any ideas?


 
Patrik Nilsson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nobody knows?

Or is the question hard to understand?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Or is the question hard to understand?

not really.

the problem is that unless someone has tried to do exactly what you're trying to do,
has experienced the exact same problems of the scenario you have posted, and come
up with a solution that they could post, then the rest of us would need to build a sample
program to observe the behavior and to experiment with to possibly find a solution.

so, your options are
1) wait for someone who has the solution
2) hope someone has spare time/energy to build a program
3) post a working program for the rest of us to play around with.
 
Patrik Nilsson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I might have to do that.

But what I want to accomplish is that the user should not be able to click on anything behind the dialog showing.
This is normally done by using a Glasspane, but maybe there are other solutions?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> But what I want to accomplish is that the user should not be able to click on anything behind the dialog showing.

just make the dialog modal

dialog.setModal(true);

or use one of the dialog constructors with a modality parameter.
 
Patrik Nilsson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well it's not really a dialog and I don't want to have it modal I want a Glasspane.
The glasspane works fine but it is still possible to "tab" behind it.
 
Mikko Kohtamäki
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it wont matter that dialog will not be in separate window.

You could try to draw/add your dialog on glasspane?

Create some JOptionPane and then JDialog by calling JOptionPane.createDialog(Component parentComponent, String title) then JDialog.getContentPane() and add that to your glasspane. Something like that would help, I haven't tried it myself yet.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!