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

4

6

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

Buddhism answered 18/5, 2012 at 11:31 Comment(5)
Of course it is. I have no idea how though. Also, your question is a bit too vagueRanice
1) It is generally a bad idea to mix PLAFs 2) Which PLAFs, and why?Beeson
Perhaps he means he wants so simulate an actual control panel. It's common for various controls to be different from one another.Hilaryhilbert
@TonyEnnis Maybe this, maybe that, maybe the other. I want to know what the OP's actual use-case is.Beeson
@AndrewThompson As would I. I offered the suggestion since the answers below imply the OP is insane. :-)Hilaryhilbert
S
6

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

Spiers answered 18/5, 2012 at 12:15 Comment(0)
D
7

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.

Dissuade answered 18/5, 2012 at 11:35 Comment(0)
S
6

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

Spiers answered 18/5, 2012 at 12:15 Comment(0)
D
1

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.

Discontented answered 18/8, 2018 at 6:4 Comment(0)
A
0

No ,you can not. Before you running your java application ,JVM will only load swingpropertitirs.propertities(a file located in you jre/lib) once , and it will only select only your default L&F ,but if you set your look and feel by adding code , it will use the L&F you selected.

Agiotage answered 18/5, 2012 at 11:43 Comment(1)
"No ,you can not." While it is not advisable to do so, this is simply incorrect.Beeson

© 2022 - 2024 — McMap. All rights reserved.