Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JFrame vs JOptionPane

 
Ranch Hand
Posts: 185
Netbeans IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With JOptionPane (and other modal JDialogs), the dialog will block access to the parent JFrame until the dialog is closed. JFrames never block access.
 
Alan Smith
Ranch Hand
Posts: 185
Netbeans IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Marshal
Posts: 69805
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but you will have a very peculiar interface. Why don’t you put the buttons on the frame?
 
Alan Smith
Ranch Hand
Posts: 185
Netbeans IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a job for a menu and/or toolbar.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic