answersLogoWhite

0


Best Answer

"Pluggable look and feel" refers to the ability to change the look and feel (LnF) of a Java program on the fly. The term is actually quite descriptive. If you change the LnF of your program, all GUI elements will have a distinctly different look to them. Windows will be drawn differently, buttons and scroll bars will look (and may respond) differently, etc.

You can change the current LnF by invoking:

UIManager.setLookAndFeel(lookAndFeel);

Probably the most useful invocation of this method uses the UIManager class to figure out what the underlying operating system is, and to use the default LnF for your program:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

This will make programs run on a Windows machine look like a Windows application, programs run on a Mac look like a Mac application, etc.

Another useful function is the UIManager.getInstalledLookAndFeels(), which will return an array of all available LnFs.

Below is a simple sample program which will demonstrate these methods.

Two things to take note of:

# Once you change the look and feel, you need to call the updateUI method on all JComponents. The good people at Sun recommend calling SwingUtilities.updateComponentTreeUI(Component). If you call this on your top level components (main frame/window), it should update all components contained within it. # UIManager.setLookAndFeel can throw a lot of exceptions. Be prepared to have a large try-catch block (or a throws clause) everywhere you set the LnF.

try {

// Start off with the system default LnF

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

// Ugly, ugly try-catch block if you catch each type individually.

} catch (final ClassNotFoundException ex) {

} catch (final InstantiationException ex) {

} catch (final IllegalAccessException ex) {

} catch (final UnsupportedLookAndFeelException ex) {

} catch (final ClassCastException ex) {

}

// Create our frame

final JFrame frame = new JFrame("LnF Test Frame");

// Set up our simple panel

final JPanel panel = new JPanel();

panel.setLayout(new GridLayout(4, 4));

// Set up a button for each installed LookAndFeel.

// When a button is pressed, the LnF will change.

for (final LookAndFeelInfo lnfInfo : UIManager.getInstalledLookAndFeels()) {

final String lnfName = lnfInfo.getName();

final String lnfClassName = lnfInfo.getClassName();

final JButton button = new JButton(lnfName);

button.addActionListener(new ActionListener() {

// Here's where we change and update the LnF

public final void actionPerformed(final ActionEvent ev) {

try {

UIManager.setLookAndFeel(lnfClassName);

SwingUtilities.updateComponentTreeUI(frame);

} catch (final Exception ex) {

}

}

});

panel.add(button);

}

// Set up and display our frame

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// (adding a scroll panel just to see some more components)

frame.setContentPane(new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS));

frame.setSize(300, 300);

frame.setVisible(true);

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the component of pluggable look and feel in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the difference between heavy weight and lightweight programing language in java script?

Applet is a heavy component,Applet uses AWT Layouts..like flow layout,Swing is a light weight component, Using UI Manager, swing have look and feel according


What are the features of java swing?

Swing is the next-generation GUI toolkit that Sun Microsystems has developed for the Java language. It is essentially a vast component framework built over parts of the older AWT component libraries used in Java 1.0 and 1.1. Swing is written in 100% Java; there are no native calls. Hence, it can run on any platform with a compatible Java virtual machine. 1. It provides Java programmers many new powerful components-- most of which we've been begging for since Java's inception. 2. It gives developers a chance to create a powerful, portable application that can not only target users on any Java-compatible platform, but also target their desired look-and-feel as well. 3. The distribution is easy to learn, but can also be used at varying levels of complexity to curtail to the programmer's wishes.


What are the advantages of swing components?

a. It provides Java programmers many new powerful components-- most of which we've been begging for since Java's inception. b. It gives developers a chance to create a powerful, portable application that can not only target users on any Java-compatible platform, but also target their desired look-and-feel as well. c. The distribution is easy to learn, but can also be used at varying levels of complexity to curtail to the programmer's wishes.


What Is The Java Enum And What Is It Used For?

The best way I can describe an enum is a class of Java language. Enums look like they are used in code string when writing a website.


How do you learn java to get certified?

You can search the web with the name of the java certification and you will get loads of online material that you can use to study and get certified. Alternately you can go to book stores and look out for books to learn Java. There are a couple of links in the related links section of this answer.

Related questions

What is the difference between heavy weight and lightweight programing language in java script?

Applet is a heavy component,Applet uses AWT Layouts..like flow layout,Swing is a light weight component, Using UI Manager, swing have look and feel according


Why would someone need a Java swing?

Java Swing might be needed by someone because Swing provides a native look and feel that matches the look and feel of several platforms, with more powerful and flexible components than AWT.


What are the features of java swing?

Swing is the next-generation GUI toolkit that Sun Microsystems has developed for the Java language. It is essentially a vast component framework built over parts of the older AWT component libraries used in Java 1.0 and 1.1. Swing is written in 100% Java; there are no native calls. Hence, it can run on any platform with a compatible Java virtual machine. 1. It provides Java programmers many new powerful components-- most of which we've been begging for since Java's inception. 2. It gives developers a chance to create a powerful, portable application that can not only target users on any Java-compatible platform, but also target their desired look-and-feel as well. 3. The distribution is easy to learn, but can also be used at varying levels of complexity to curtail to the programmer's wishes.


Abbrevation for JAVA?

"Java" doesn't stand for anything. For some reason wikianswers has Java in capitals, which makes it look like its an abbreviation.


What are the advantages of swing components?

a. It provides Java programmers many new powerful components-- most of which we've been begging for since Java's inception. b. It gives developers a chance to create a powerful, portable application that can not only target users on any Java-compatible platform, but also target their desired look-and-feel as well. c. The distribution is easy to learn, but can also be used at varying levels of complexity to curtail to the programmer's wishes.


What is AWT and Swing in java?

Swing is a library of GUI controls. Classes in swing are not OS dependent. They do not take the look and feel of the target platform so that they have a consistent appearance.


Where is the east coast of Java?

the east coast of Java is in the east so look to your right on the map


How does Java Script enhances webpages?

Java Script allows client side modifications. In simple terms the websites which let you change the look and feel, drag & drop items, have good animations, image sliders, slideshows are more or less being done using java script. Ofcourse other languages and technologies are used but java script is the most commonly used in those scenarios.


How do I learn mobile application development?

well you should start by specializing in what programming language you want to code in. for example java and look up java tutorials on youtube and look up tutorials elsewhere. then for example java will branch off into somthing like Java Me ( java and java me are two different things) but you need to learn a certain language before learning about specific development. look into Java or C++ or another base language, then work your way into mobile device development. this will take time and patience to learn.


What is swings in java?

Swing is the next-generation GUI toolkit that Sun Microsystems has developed for the Java language. It is essentially a vast component framework built over parts of the older AWT component libraries used in Java 1.0 and 1.1. Swing is written in 100% Java; there are no native calls. Hence, it can run on any platform with a compatible Java virtual machine. 1. It provides Java programmers many new powerful components-- most of which we've been begging for since Java's inception. 2. It gives developers a chance to create a powerful, portable application that can not only target users on any Java-compatible platform, but also target their desired look-and-feel as well. 3. The distribution is easy to learn, but can also be used at varying levels of complexity to curtail to the programmer's wishes.


What are the best places to look for a Java Enum tutorial?

The best places to look for a Java Enum tutorial would be at an office supply store. Staples Business Depot often carries Java tutorials at a very low price.


Is there an job opportunity after learning java?

There are a lot of jobs available in the Java Programming field. You might want to go to http://www.dice.com and search for JAVA jobs in your area. I'm sure you can find entry level Java developer positions if you look!