Solved

JOptionPane position in a JDesktopPane within a JScrollPane

Posted on 2002-05-27
10
762 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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 100 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet requestdispatcher include and forward differences 1 39
couple of eclipse 5 46
Oracle SQL syntax check  without executing 6 75
table example 4 32
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

830 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