aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JFrame vs JOptionPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFrame vs JOptionPane" Watch "JFrame vs JOptionPane" New topic
Author

JFrame vs JOptionPane

Alan Smith
Ranch Hand

Joined: Oct 19, 2011
Posts: 152

Hi,

I am building an application that has a main gui built with a jframe and has buttons such as load, save (text from text areas), etc. When I use these buttons i create a new jframe as a pop up menu for each button. Now I have just discovered JOptionpane. Is there any reason to use JOptionPane over the JFrames for this kind of scenario? Are JFrames heavy on memory in comparison, etc? If anyone knows the advantages/disadvantages could you let me know because I am going to stick with JFrame windows for all my 'pop up' menus.

Cheers
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

With JOptionPane (and other modal JDialogs), the dialog will block access to the parent JFrame until the dialog is closed. JFrames never block access.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Alan Smith
Ranch Hand

Joined: Oct 19, 2011
Posts: 152

Rob Spoor wrote:With JOptionPane (and other modal JDialogs), the dialog will block access to the parent JFrame until the dialog is closed. JFrames never block access.


But can I still manipulate components on the main frame using the optionpane ie. Could I use a button on the option pane that will save the text from a textarea on the main gui.

Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38784
    
  23
Yes, but you will have a very peculiar interface. Why don’t you put the buttons on the frame?
Alan Smith
Ranch Hand

Joined: Oct 19, 2011
Posts: 152

Campbell Ritchie wrote:Yes, but you will have a very peculiar interface. Why don’t you put the buttons on the frame?


yes I know that but I was just making sure. I have a lot of different options like load, save, etc so I think its best to have pop up windows to hold all the relevant options for each button ie, confirm choice, etc.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4542
    
    5

Sounds like a job for a menu and/or toolbar.


luck, db
There are no new questions, but there may be new answers.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

first: what rob said, JOptionPane dialogs are modal
and IMO they are mainly a convenience when you need a simple modal dialog. most of the time that is all you need.
i also think Darryl might be right. if you have a great many buttons, some might be better as menu items. it will make the GUI less cluttered. especially actions like save and load are generally menu choices.furthermore, saving and opening files is usually handled by a JFileChooser which displays its own dialog.


SCJP
Visit my download page
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JFrame vs JOptionPane