Solved

JOptionPane position in a JDesktopPane within a JScrollPane

Posted on 2002-05-27
10
777 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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:
Suggested Courses

615 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