Different Look And feel for different component

How can we ensure that in the same application we have a metal-look and feel for JTable and window look and feel for JTree ? Basically is it possible to have different look and feel for different component in the same application
[243 byte] By [santoshba] at [2007-11-27 0:38:26]
# 1
Set the L&F using the UIManager (I think). Then call the updateUI() on the component.You realize that having different L&F will most likely be confusing for the end user?
rkippena at 2007-7-11 22:49:22 > top of Java-index,Desktop,Core GUI APIs...
# 2

> Basically is it possible to have different look and

> feel for different component in the same application

No. The implementation of the look-and-feel layer in Swing is not designed to support mix-and-match of UI delegates from different look and feels. One of the reasons is the "singletonness" approach of UIManager which is kind of a central repository for the current LAF.

kirillga at 2007-7-11 22:49:22 > top of Java-index,Desktop,Core GUI APIs...
# 3

import javax.swing.*;

import java.awt.*;

public class SimpleEx extends JPanel {

JButton b1 = new JButton("b1");

JButton b2 = new JButton("b2");

public SimpleEx() {

setLayout(new FlowLayout());

add(b1);

add(b2);

}

public static void main(String[] args) throws Throwable {

JFrame f = new JFrame();

SimpleEx p = new SimpleEx();

f.setContentPane(p);

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

p.b2.updateUI();

f.pack();

f.setVisible(true);

UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

}

}

rkippena at 2007-7-11 22:49:22 > top of Java-index,Desktop,Core GUI APIs...
# 4

While a trivial example will work, it doesn't scale to real UIs (unless, of course, you have one static frame with two buttons...) Simply put, the very fact that UIManager holds all the information on the currently installed LAF jeopardizes the functionality of UI delegates from another LAF (installed on some of your UI components).

In short, it's like the multi-threaded programming - it may work in your dev box, but when it hits the production and goes terribly wrong, you'll have no idea where to look. Do not do this.

kirillga at 2007-7-11 22:49:22 > top of Java-index,Desktop,Core GUI APIs...
# 5

Agreed that UIManager and Swing has been designed to have a appl one look and feel, and it is not recommended to have two different look and feel for different component of the same application.... But i just wanted to know if we can do it. And example given by rkippen works..

Thank you all.

Santosh.Bhushana at 2007-7-11 22:49:22 > top of Java-index,Desktop,Core GUI APIs...
# 6
> And example> given by rkippen works..Sigh...
kirillga at 2007-7-11 22:49:22 > top of Java-index,Desktop,Core GUI APIs...
# 7
Sorry, Could not able to get (kirillg's comment)On the same thought, can we create a custom look and feel where we have one have one a metal look and feel for all tree component and a different look and feel for say JTable component.
santoshba at 2007-7-11 22:49:22 > top of Java-index,Desktop,Core GUI APIs...
# 8

> On the same thought, can we create a custom look and

> feel where we have one have one a metal look and

> feel for all tree component and a different look and

> feel for say JTable component.

This is how all third-party look and feels are written, extending Metal / Basic / Windows base class (LookAndFeel) and the corresponding UI delegate classes.

kirillga at 2007-7-11 22:49:22 > top of Java-index,Desktop,Core GUI APIs...