?
Solved

Where in an app should UIManager.setLookAndFeel be run?

Posted on 2009-02-18
8
Medium Priority
?
310 Views
Last Modified: 2013-11-23
What is best practice for running the method mentioned in the subject? The app I'm writing is managed by a controller class that e.g. starts the main gui frame. Should it be run in the constructor of the gui frame? Or should it be run before that in the controller class (and is this possible at all)? I'm writing my app for a school project so best practices matters just as much as making the app be effective.
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

Open in new window

0
Comment
Question by:Suppai
  • 4
  • 4
8 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 500 total points
ID: 23670307
That should be done as the first line in the Runnable of invokeLater at startup
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 23670356
As in
    public static void main(String[] args) {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {  	
		    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());			
                    X x = new X();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Open in new window

0
 

Author Comment

by:Suppai
ID: 23670375
Woah there some Thread knowledge i miss there:-) Thats next to learn, but now we are at it, how should a gui be run Threadwise? The Controller class, I know, ought to be run in a separate thread as it is supposed to listen for server responses at a given frequency provided by the client user, but I haven't quite got the facts about Threads straight yet, but any pointers are of course appreciated although I might save it for a separate question:-)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:Suppai
ID: 31548245
Didnt see your second post when I wrote mine, that seems to take care of the gui frame part.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 23670406
The best practice is to start the GUI in the event dispatch thread - that's what the above does
0
 

Author Comment

by:Suppai
ID: 23670577
Can it be done in a more un-nested way? Anyways I kinda can't make it work, the thread terminates instead of showing the frame. Maybe I did something wrong (I have attached the code)? Does the gui frame have to implement runnable or something like that? Furthermore I was thinking of starting the gui by a controller class (complete with a main method) to implement a MVC design, is that a good way to get i as MCV-like as possible or should the gui be started first and then the controller. Doesnt have a clue whats the "proper" way to do it in java.
	public ClientController(){
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {  	
                	try {
						UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
					} catch (Exception e) {						
					}		
					MainFrame frame = new MainFrame("Title",FileHandler.readSettings());
                	frame.setVisible(true);
                }
            });
        }catch(Exception ex){
        }finally{
        }
	}

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 23670620
No that should be done in main
0
 

Author Comment

by:Suppai
ID: 23673681
Still when Im doing it in main it terminates, heres the code:
	public static void main(String[] args){
		try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {  	
                	try {
						UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
					} catch (Exception e) {						
					}		
					MainFrame frame = new MainFrame("Doek Inc Web Tracker",FileHandler.readSettings());
					frame.setVisible(true);
                }
            });
        }catch(Exception ex){
        }
	}

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month17 days, 7 hours left to enroll

864 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