Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set different look and feel for different components?

I have a number of components on panel and I want to apply different look and feel to different components. Is it possible?

like image 239
Azuu Avatar asked May 18 '12 11:05

Azuu


People also ask

How do you set your look and feel?

setLookAndFeel() − To set the look and feel of UI components. JFrame. setDefaultLookAndFeelDecorated(true); − To change the look and feel of the frame.

What is look and feel in Java?

The architecture of Swing is designed so that you may change the "look and feel" (L&F) of your application's GUI (see A Swing Architecture Overview). "Look" refers to the appearance of GUI widgets (more formally, JComponents ) and "feel" refers to the way the widgets behave.


3 Answers

Yes,

you can do it. See Mixing look and feel

BUT

It's not recommended, and, frankly, it's ugly. Why would you want to do that? Is there something specific you wish to do? Perhaps there's a better way.

like image 136
Ewald Avatar answered Oct 01 '22 02:10

Ewald


I have a number of components on panel and I want to apply different look and feel to different components. Is it possible?

Yes is possible, don't do it, because most of Look and Feel have got different

  • Color, Font, Foreground, Background

  • Size or PreferredSize on the screen

  • use another methods from API for LayoutManager

  • implemented various methods in the JCOmponents APIs e.g. Color, Font, Foreground, Background

  • simple answer ---> is possible to create a awfull mess on the screeen

I'd suggest to use todays Java Look and Feels, most of them have various colors themes, part of them seperates themes and with option to change Colors themes, then there you can mixing built-in themes or/and with Color themes for each of JComponents

I think that with success you can to set Color, Font, Foreground, Background only, Look and Feels required basic knowledge about how JComponents and/with LayoutManagers together works

like image 36
mKorbel Avatar answered Oct 01 '22 04:10

mKorbel


I know I am late but I think someone might be use this it is kind of hack that I use to put multi look and feel to the app: put this the look and feel chooser before initiating the item (before writing = new ...)

try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Windows".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
    | UnsupportedLookAndFeelException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

and then return the UIManager look and feel to the look and feel that it was on before you do this after it as in the example below:

JButton test;
try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Windows".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
    | UnsupportedLookAndFeelException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
test = new JButton();
try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Mwtal".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
    | UnsupportedLookAndFeelException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Like this only the button test will have the look and feel of the windows and the rest will have look and feel of Metal.

Hope this hack help someone.

like image 28
Sparks Avatar answered Oct 01 '22 02:10

Sparks