I am using Java 1.3.1 on a Linux System.
I have spent mucho time getting the JPopupMenu.show to work the way I
require.
My End User enters an equal sign in the Forms JTextField that triggers an
Event that uses JPopuMenu to present a set of 4 Menu's that shall fetch a
Text String to be placed in the associated JTextField.
For the first 3 Menu Selections I use (0,0) to place the menu in the upper
left hand corner of my invoker [JPanel]. This is fine because the Menu Items
are sometimes long,
For the final JPopupMenu I am required to display it under the Forms
invoking JTextField. I spent considerable time getting the required (x,y)
coordinates to use in the JPopupMenu.show Method. This works fine as long as
the selected JTextField is within the first page of my scrollable form.
However, when I test a JTextField in the lower portion of a Scrollable
invoker [JPanel] the 4th JPopupMenu appears anywhere it wants to and most of
the time it is unseen or disappears when I move the mouse toward it. Very
flaky!
If I use the (0,,0) parameters for this 4th Menu it works fine but would not
be as user friendly IMHO.
About the Scrollable Panel:
It is a JPanel Instance and I use the 'JPanel.setPreferredSize' and
JPanel.scrollRectToVisible' methods to manage the Scrollable Panel. It works
fine except for the above problem.
Questions:
1.. Is there a know problem with this Class and if so does SDK 1.4.1 fix
it.
2.. Any suggestion on what else I should try. I have used println
statements to verify that the (x,y) coordinates are OK.
Regards,
Jim.
Andrew Thompson - 26 Jan 2004 22:18 GMT
"Jim Crowell" ...
| 1.. Is there a know problem with this Class...
Do not know. Have you checked the Sun site?
| 2.. Any suggestion on what else I should try.
Some guru may jump in with the answer
soon. Failing that I would suggest..
http://www.physci.org/codes/sscce.jsp
--
Andrew Thompson
* http://www.PhySci.org/codes/ Web & IT help
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
Jim Crowell - 27 Jan 2004 15:47 GMT
Andrew,
> | 1.. Is there a know problem with this Class...
>
> Do not know. Have you checked the Sun site?
Yes and I found a slew of bug entries but none that seemed to help me.
I wish I had looked before I stated using JPopupMenu.
Hopefully I would have been smart enough not to enven try it.
> | 2.. Any suggestion on what else I should try.
>
> Some guru may jump in with the answer
> soon. Failing that I would suggest..
> http://www.physci.org/codes/sscce.jsp
Thanks. Perhaps I can re-invent the problem this way but it would take
consiserable time.
I really think that the complexity of my App is leading up to the problem
somehow.
The JTextField I mentioned is really a custom class with many properties for
servicing multiple fields of a form.
There is the main Form JPanel hosting a collection of my custom class alone
and / or a collection of JPanel's hosting my custom Class.
I also have my own Focus Manager Class that may contribute to the problem.
For now I'll just use the (0,0) JPopupMenu.show coordinates and try to
highlight the 4th Menu somehow to make it more user friendly.
Eventually I'll most likely replace the JPopupMenu usage with a JDialog
hosted Window that does what I require.
This seems to be my history with Java. I started this project using Java
1.0.4 and from that point on I have always had "Focus" problems and when I
try to use something that adds some nice capabilities [like JPopupMenu] I
spend days trying to get it to work but generally have to revert to a "Work
Around".
Most likely the problems are caused mostly by me!
Thanks for the help,
Jim...
Chris Smith - 27 Jan 2004 16:20 GMT
> For the final JPopupMenu I am required to display it under the Forms
> invoking JTextField. I spent considerable time getting the required (x,y)
[quoted text clipped - 5 lines]
> the time it is unseen or disappears when I move the mouse toward it. Very
> flaky!
Sounds like you have not calculated the position correctly. That can be
tricky when you've got a JViewport involved. Can you post the code
you've used to do this?
(JViewport is used internally be JScrollPane, so if you're scrolling
with JScrollPane then yes you do have a JViewport in your component
hierarchy.)

Signature
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Jim Crowell - 27 Jan 2004 18:03 GMT
Chris,
>> However, when I test a JTextField in the lower portion of a Scrollable
> > invoker [JPanel] the 4th JPopupMenu appears anywhere it wants to and most of
[quoted text clipped - 4 lines]
> tricky when you've got a JViewport involved. Can you post the code
> you've used to do this?
I could but it is quite involved.
It took me a long time to get my variable length form to scroll properly
but it works fine now except for this JPopupMenu usage.
> (JViewport is used internally be JScrollPane, so if you're scrolling
> with JScrollPane then yes you do have a JViewport in your component
> hierarchy.)
Yes I am using JScrollPane and I am aware of JViewport.
I have a JPanel [showPanel] that contains all my objects to be displayed.
The 'showPanel' changes it size often. The App user may add or remove rows
of Form Fields at will.
Each time I re-display 'showPanel' I call the 'showPanel.setPreferredSize'
method
so that the JViewport knows the current size of the JPanel. I also use the
'showPanel.scrollRectToVisible' method in an attempt to ensure that the
current object with focus is displayed properly.
I still have some problems when the Form gets very long but for most forms
the scrollable display is fine.
I have verified with 'println' statements that the (x,y) coordinates are
computed
properly and that they fall within the range of coordinates specified in the
'showPanle.setPreferredSize' method call.
Can you think of any other methods I need to call to manage the JPanel /
JScrollPane / JViewport
objects?
Thanks,
Jim...