swing JInternalFrame focus management

E

epicwinter

I am doing a lot of work with a JInternalFrame based gui. I have one
desktoppane and hundreds of possible JInternalFrames that can be opened
and closed within it. There are often layers of JInternalFrames sitting
on top of each other, many are derived from each other. My problem is
that when a JInternalFrame is disposed or hidden then the
JInternalFrame below it is visible but it does not automatically gain
focus. My application is very keyboard friendly and enables the user to
do most things by typing and hotkeys. But when a JInternalFrame closes
and then nothing has focus they have to take their mouse and manual
click on it before they can start typing again.
So I am wondering if there is a reasonable way to manage it so when a
jinternalframe is closed the layer beneath automatically gains focus?
thanks
ryan
 
A

Andrei Kouznetsov

I am doing a lot of work with a JInternalFrame based gui. I have one
desktoppane and hundreds of possible JInternalFrames that can be opened
and closed within it. There are often layers of JInternalFrames sitting
on top of each other, many are derived from each other. My problem is
that when a JInternalFrame is disposed or hidden then the
JInternalFrame below it is visible but it does not automatically gain
focus. My application is very keyboard friendly and enables the user to
do most things by typing and hotkeys. But when a JInternalFrame closes
and then nothing has focus they have to take their mouse and manual
click on it before they can start typing again.
So I am wondering if there is a reasonable way to manage it so when a
jinternalframe is closed the layer beneath automatically gains focus?

it is _done_ automatically (at least in 1.4)!
May be you have some error in your code?
 
E

epicwinter

If that is the case I would be estatic. Do you have to do something to
activate it? What makes you think this is done? I don't think there
is an error in my code. I have a JFrame which holds a jdesktop pane in
it's content pane and I add the jinternalframes to the desktop pane
like so:
desktopPane.add(aJInternalFrame);
thanks ryan
 
A

Andrei Kouznetsov

If that is the case I would be estatic. Do you have to do something to
activate it? What makes you think this is done? I don't think there
is an error in my code. I have a JFrame which holds a jdesktop pane in
it's content pane and I add the jinternalframes to the desktop pane
like so:
desktopPane.add(aJInternalFrame);

I just tried it and it worked. I also tried to add frames to different
Layers and it worked.

You should check, may be some another component consumes focus.
Try to add InternalFrameListener to your JInternalFrames and in
frameClosed()
try to check which component getting focus.
You can also use such listener to set focus.
Or you can write your own DesktopManager (may be the best solution).
 
E

epicwinter

I had to write my own desktop manager that automatically activates the
top frame when another frame is deactivated.
 
Joined
Nov 10, 2008
Messages
1
Reaction score
0
jInternalFrame focus problem

Ryan,
I am having the identical problem that you describe. When I close the current frame, the focus does not go to the first focusable field on the next available frame. I can't get the focus without clicking with the mouse. But this is not good enough as my app must be accessable without the mouse. I have tried putting an internalframe listener on the frame that is supposed to be getting the foucus. Within the focus listener, I try to force the focus by executing requestFocusInWindow on the first focusable field, as follows. It doesnt' work.

public void internalFrameActivated(InternalFrameEvent e) {

getPgDefIdField().requestFocusInWindow();
}

What is curious though (and this is probably at the heart of the probem), is that when I run the code through the debugger, the frame that has been closed is still visible on the screen when the focus has already passed to the new frame containing the code above. The new frame is actually activiated. The code above executes, but since the old frame is still visible, the focus is never given to the getPgDefIdField textbox on the new frame. The old frame does not disappear until after the listener code has executed.

For me, writing my own desktop manager is not an option. I am already committed to using Scrollablable Desktop in an enterprise setting. Any suggestions?

Pete Grant
 
Joined
Jul 13, 2010
Messages
1
Reaction score
0
Have you ever come to a satisfying solution on this one? We intend to implement a fully keyboard operated application with internal frames.

To gain the focus on an internal frame we implemented this, which is not really elegant:
Code:
            @Override
            public void internalFrameActivated(final InternalFrameEvent e) {
                if (firstActivation) {
                    firstActivation = false;
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                JComponent comp = DataViewer.getSubcomponentByName(e.getInternalFrame(), SearchModel.SEARCHTEXT);
                                comp.setFocusable(true);
                                comp.setRequestFocusEnabled(true);
                                comp.requestFocus();
                            } catch (Exception e1) {
                                //ignore
                            }
                        }
                    });
                }
            }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top