I have a number of components on panel and I want to apply different look and feel to different components. Is it possible?
setLookAndFeel() − To set the look and feel of UI components. JFrame. setDefaultLookAndFeelDecorated(true); − To change the look and feel of the frame.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With