tags:

views:

223

answers:

3

I have heard that there are 2 ways that we can set the PLAF in Swing. What is the real meaning of PLAF, and what are those 2 ways?

+2  A: 

Observer Pattern.

Some of the most notable implementations of this pattern:

  • The Java Swing library makes extensive use of the observer pattern for event management.
JG
What's the real difference between Observers and standard publish subscribe?
Uri
I'd say that Observer is applied to software design situations (a software design pattern), whilst publish/subscribe is more general and refers to a messaging paradigm, that is commonly implemented in middleware.
JG
+1  A: 

To answer the question in your title: Observer is the design pattern that Swing employs.

PLAF is a 'Pluggable Look And Feel'. Here is a reference for PLAF in Java.

The title, regarding the Event Listeners, and the PLAF are not related. The former has to do with the processing of events - more closely associated with the C in MVC, while the latter is generally associated with the View aspect of MVC.

akf
Tom Hawtin - tackline
A: 

PLAF = Pluggable Look and Feel. Basically, the same UI can have different skins with very little work.

Check out this site for a detailed description of L&F. In short, there are actually 3 ways to set up your PLAF.

1) Via command line: java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel MyApp or java -Dswing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel MyApp

2) Via swing.properties file in your java lib. swing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel

3) Programatically with either:

//At the beginning of your program
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
//Another option
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
//And another
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

//Or during your program - 
UIManager.setLookAndFeel(lnfName);
SwingUtilities.updateComponentTreeUI(frame);
frame.pack();

The above link also has code examples to demonstrate how to change your look and feel.

Hope that helps!

Andres