Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swing GUI - Creating a 'Settings' Window (Properly)

I am working on an application that uses Swing. I have successfully created a main GUI for the user to work from. However, I would like to allow the user to change his/her settings. How should I go about creating the settings window? Would using a new JFrame called 'Settings' be the best way to handle this, or is there something better to use than a second JFrame?

(Note: The settings JFrame, on exit, will not close the main GUI, it will use the DISPOSE method)

I would like to handle this in a way that consumes the least amount of memory, but maintaining a professionalized look to the application.

like image 849
Anthony Avatar asked Apr 11 '12 18:04

Anthony


People also ask

What is the importance of using panels when adding GUI or controls in a Java program?

It allows you to group components together, it allows you to devise complex interfaces, as each panel can have a different layout, allowing you to leverage the power of different layout managers.

Is JOptionPane a GUI?

JOptionPane is a nice way to throw together a few dialog boxes and get a GUI, but it doesn't give us the flexibility we really want. But with power and flexibility come complexity. The basic class we start with is a JFrame.


2 Answers

Have you considered a CardLayout? http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html

Personally, I find the use of a separate dialogue to be a bit dated for configuration settings. I prefer tabbed layouts, which are card layouts decorated with a tab bar across the top.

You could easily wrap your application in a near-top-level card layout and add a menu action to switch to the configuration card, with the "acknowledgement" or "cancel" buttons switching back to the main application card.

In the end, it is really about what your users prefer, but remember a lot of them might prefer what they know, even if it is not a better solution. You have to find a balance, and if your implementation rocks, then eventually they will want your approach to the problem to be used in other applications.

A perfect example of this is tabbed browsing, as opposed to multiple windows. Personally, I can't imagine going back to multiple-window browsing now that I have become accustomed to browsing tabs, but at one point in time, multiple windows was the only game in town.

In the end, if you find out you made the wrong choice, keep you code clean enough to easily implement with either solution. As long as your configuration screen is just a plain JPanel (or wrapped in just a JPanel), it shouldn't be very hard to do.

like image 173
Edwin Buck Avatar answered Oct 17 '22 01:10

Edwin Buck


here is a class that does just this kind of thing:

http://tus.svn.sourceforge.net/viewvc/tus/tjacobs/ui/dialogs/ParamDialog.java?view=log

like image 41
ControlAltDel Avatar answered Oct 17 '22 01:10

ControlAltDel