I have a number of components on panel and I want to apply different look and feel to different components. Is it possible?
-
Of course it is. I have no idea how though. Also, your question is a bit too vague – keyser May 18 '12 at 11:32
-
11) It is generally a bad idea to mix PLAFs 2) Which PLAFs, and why? – Andrew Thompson May 18 '12 at 11:34
-
Perhaps he means he wants so simulate an actual control panel. It's common for various controls to be different from one another. – Tony Ennis May 18 '12 at 12:20
-
@TonyEnnis Maybe this, maybe that, maybe the other. I want to know what the OP's *actual* use-case is. – Andrew Thompson May 18 '12 at 12:32
-
1@AndrewThompson As would I. I offered the suggestion since the answers below imply the OP is insane. :-) – Tony Ennis May 18 '12 at 12:35
4 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.
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
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.

- 496
- 7
- 16
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.

- 1
-
3*"No ,you can not."* While it is not advisable to do so, this is simply incorrect. – Andrew Thompson May 18 '12 at 11:46