This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Help File Focus Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Help File Focus Issue" Watch "Help File Focus Issue" New topic
Author

Help File Focus Issue

Vengan Krish
Ranch Hand

Joined: Mar 05, 2005
Posts: 32
Hi,
I'm kind of stuck in a silly problem. I did my html help file with hyperlink listener, all works fine except one issue - when I click on the Help menu item, the frame comes up but goes and hides behind the main window. Just to simply the problem, I removed all logic and did a test program and was able to recreate it.
Here is my test case:
- A simple Hello World frame window with an editable combobox, a button and one menu item. Menu item and button have same action command.
- The menu/button action handler simply creates an empty frame window (let's call it help file) and displays.
- here is where it gets funnier - if I click on menu, the help file hides behind. if I click on button, it comes in the front and gets focus.
- If I make the combobox non-editable, everything works fine.
- If I invoke menu using keyboard accelerator, it works fine

If I make help file a JDialog it works fine but without control menu (min, max, close) - so I didn't go for it.
Here is the test case's code which will run as is.
I would greatly appreicate your inputs on this.

import javax.swing.*;
import java.awt.Dimension;
import java.awt.event.*;

public class helpmission implements ActionListener{

public static void main(String[] args) {
helpmission v= new helpmission();
v.showGUI();
}

void showGUI() {
JPanel searchPanel;
JFrame frame;
JMenuBar menuBar;
JMenu menuHelp;
JMenuItem menuItem;

JFrame.setDefaultLookAndFeelDecorated(true);

//Create the frame
frame = new JFrame("Hello World");
frame.setSize(new Dimension(500, 200));

//handle the close operation with event handler
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//create and add all GUI componenets
searchPanel = new JPanel();
JComboBox a= new JComboBox();
searchPanel.add(a);
a.setEditable(true);

JButton b= new JButton("Contents");
searchPanel.add(b);
b.addActionListener(this);
searchPanel.add(b);

menuBar= new JMenuBar();
frame.setJMenuBar(menuBar);

menuHelp= new JMenu("Help");
menuHelp.setMnemonic(KeyEvent.VK_H);
menuItem= new JMenuItem("Contents", KeyEvent.VK_C);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_C, ActionEvent.ALT_MASK));

menuHelp.add(menuItem);
menuItem.addActionListener(this);

menuBar.add(menuHelp);

frame.getContentPane().add(searchPanel);
frame.setVisible(true);
}

public void actionPerformed(ActionEvent event) {
if (event.getActionCommand().equals("Contents")) {
JFrame f= new JFrame("Hello World Help File");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300, 300);
f.setVisible(true);
}
}
}


SCJP 1.4<br />SCJD 1.4<br />SCWCD 1.4<br />SWBCD (Preparing)
Frans Janssen
Ranch Hand

Joined: Dec 29, 2004
Posts: 357
Hi Vengan,

Does the code above demonstrate the problem? Because if I compile and launch it and I select the Help menu item, the help window pops up on top of the main window nicely. (I ran it on Windows 2000.)

Frans.


SCJP 1.4, SCJD
Vengan Krish
Ranch Hand

Joined: Mar 05, 2005
Posts: 32
Hi Frans,
Thanks for taking time.
Yes, this code is intended to demonstrate the problem.
It happens consistently for me on Windows XP.
Could somebody try this on an XP machine please?

Regards
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Vengan,

I tested it on Win XP and have the same behavior you described.

Regards
Darya


SCJP, SCJD, SCWCD, SCBCD
Vengan Krish
Ranch Hand

Joined: Mar 05, 2005
Posts: 32
Thanks Darya.
Assuming it's something to do with OS, I'm looking for a workaround.
Could we have control menu on a JDialog?
Is JInternalFrame an option?
I'm sure I'm complicating a simple stuff. Swing has been my nemesis since the beginning. This is where I have spent most time in the project more than locking.

Regards
Eric Chang
Ranch Hand

Joined: Jan 27, 2004
Posts: 113
You could always take the short cut method and just port your HTML help file to a text file and not have to worry about the focusing issue. I've had numerous issues with focusing in Swing on different platforms before...and it has caused me lots of headaches.
I did however compile your code (with Java 1.5) on an XP machine and it worked fine (both times the Help Window appeared on top of the main frame).
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
Hi Vengan,

I tested it on my XP machine, and did not have any problems. The help window poped up in front just as expected. So I don't believe the issue is OS related. What version of Java are you running?


“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Vengan Krish
Ranch Hand

Joined: Mar 05, 2005
Posts: 32
Paul,
Here is my java -version.
java version "1.4.2_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03)
Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)

I tried on 2 machines - at home, work.

Thanks
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
I am running Java 5.0 at work. I have another machine that has 1.4.2 in a seperate office. I will be there in an hour or so, so I can try it there and see if there is a focus issue on that build.
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Vengan,

my is java version "1.4.2_05" on Win XP.

Regards,
Darya
Vengan Krish
Ranch Hand

Joined: Mar 05, 2005
Posts: 32
Thanks Darya. I can't wait to hear from Paul. I am checking the forum every 15 mins.

Regards
Frans Janssen
Ranch Hand

Joined: Dec 29, 2004
Posts: 357
Hi Vengan,

I am at home now, where I am using XP.

When I compile and run it for JDK1.5 I get the correct behavior: the help window pops up in the foreground. However, on JDK1.4.2 it pops up behind the main window.

So it seems that it is indeed related to the JDK version, not the OS...

Frans.
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
Hi Vengan,

I ran it on 1.4.2_06 b3 and it worked fine...
I ran it on another machine with 1.4.2_04 and the help window poped up behind it.


My guess it that it is a behavior dependant on the particular JVM.
[ March 16, 2005: Message edited by: Paul Bourdeaux ]
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
Have you tried using the toFront() method to force the JFrame to the front and make it the active window?
Vengan Krish
Ranch Hand

Joined: Mar 05, 2005
Posts: 32
Thanks Frans and Paul.
Guess what? I tried everything toFront, toBack, requestFocus, requestFocusInWindow, transferFocus and some more methods in the frame ancestor classes.
I would be happy if I could find an alternative. I'm wondering how others would have handled help file. I'm sure many would have had this combination Jave 1.4.2/XP.
I'd appreciate if you could give me tips on possible workarounds.

Regards
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Here we go my friend . You have now two classes.



And this one is new:



The rest is for you

Regards,
Darya
[ March 16, 2005: Message edited by: Darya Akbari ]
Vengan Krish
Ranch Hand

Joined: Mar 05, 2005
Posts: 32
Darya,
Thanks and appreciate your time very much.
Your code brings up actually an instance of JDialog. As I have mentioned in my previous posts, this is something that does meet our need, except for the control menu on the top right corner (to maximize, minimize and close). In my opinion this is a bare minimum requirement for any GUI.
I thank your time again...

Regards
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Vengan,

You are welcome.

Regards,
Darya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help File Focus Issue