?
Solved

JOptionPane position in a JDesktopPane within a JScrollPane

Posted on 2002-05-27
10
Medium Priority
?
793 Views
Last Modified: 2008-02-01
Hi,

I have implemented a scrollable workspace which is a JDesktopPane inside of a JScrollPane. When I use JOptionPane.showInternalXXXX() the option pane appears centered over the desktop pane, which may or may not be visible in the viewport of the scroll pane (the code that actually does this is in JOptionPane.createInternalFrame()). I would prefer to have the option pane appear centered over the visible viewport rather than the entire desktop pane but the modal nature of the option panes prevents me from repositioning anything after creation.

I have already tried overriding the createInternalFrame() method with one of my own, but modality requires package-private calls (JInternalFrame.startModal()) which cannot be accessed from my new method.

Is there a clean way to make an internal option pane centered on an arbitrary unit, rather than the highest JDesktopPane?

Thanks in advance.
0
Comment
Question by:buri
  • 6
  • 4
10 Comments
 
LVL 92

Expert Comment

by:objects
ID: 7037828
You need to create your own option pane 'manually'.
0
 

Author Comment

by:buri
ID: 7044242
Please elaborate on this statement.

I have tried creating a JOptionPane and placing it inside of a JInternalFrame, but this does not accurately mimick the behaviour of the modal JDialog. The JOptionPane's internal methods accomplisht his by calling package-private methods which I cannot access without placing my code in the javax.swing package.

Thanks.
BU
0
 
LVL 92

Expert Comment

by:objects
ID: 7045595
Create an JOPtionPane object directly via one of it's ctor. Then create your JDialog using the createDialog() method, and place this dialog where you require it.

JOptionPane pane = new JOptionPane(.....
JDialog dialog = pane.createDialog(viewport, "Title");
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:buri
ID: 7046562
There is no problem with the JDialog -- it's the INTERNAL variety that I need to circumvent. All of my external option panes function correctly.

Thanks.
BU
0
 
LVL 92

Expert Comment

by:objects
ID: 7046570
Sorry that should have said createInternalFrame(...
0
 
LVL 92

Expert Comment

by:objects
ID: 7046571
What do you pass as the frame parent?
Have you tried using the viewport?
0
 

Author Comment

by:buri
ID: 7046604
The parent must be a child of the desktop pane within the viewport, otherwise JOptionPane.createInternalFrame() will exit on a NPE at line 1118, where it tries to center on the desktop pane ancestor.
0
 
LVL 92

Accepted Solution

by:
objects earned 400 total points
ID: 7046611
Then just set the frame location manually:

JOptionPane pane = new JOptionPane(.....
JInternalFrame frame = pane.createInternalFrame(parent, "Title");
frame.setBounds(...
0
 

Author Comment

by:buri
ID: 7046619
This seems to work appropriately. Thanks for your help!
0
 
LVL 92

Expert Comment

by:objects
ID: 7046624
No worries :-)

http://www.objects.com.au/staff/mick
Brainch MVP for Java 1
http://www.brainbench.com
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month15 days, 5 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question