• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help File Focus Issue

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
}
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Vengan Krish
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vengan,

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

Regards
Darya
 
Vengan Krish
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Vengan Krish
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vengan,

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

Regards,
Darya
 
Vengan Krish
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Darya. I can't wait to hear from Paul. I am checking the forum every 15 mins.

Regards
 
Frans Janssen
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried using the toFront() method to force the JFrame to the front and make it the active window?
 
Vengan Krish
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vengan,

You are welcome.

Regards,
Darya
 
straws are for suckers. tiny ads are for attractive people.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic