简体   繁体   中英

How to set a different Look & Feel for a JTable?

Is it possible to set different L&F to specific component (in my case JTable ) than is already used? If so, how to do it?

Edit: I wrote this piece of code according to this tutorial . Why is this code not working? No fails or exceptions, but JTable is still the same.

NimbusLookAndFeel nb = new NimbusLookAndFeel();
jTable1.putClientProperty("Windows.Overrides",nb.getDefaults());
jTable1.putClientProperty("Windows.Overrides.InheritDefaults",false);

If you would like to apply the Nimbus L&F to a button, then you simply need to figure out which class that is responsible for rendering Nimbus buttons. The process is just the same as if you want to apply your very own custom L&F, where you set your own UI class on the button.

You can refer the below URL for all UI default values for nimbus look and feel

http://jasperpotts.com/blogfiles/nimbusdefaults/nimbus.html

Go to Table section and use all the those Table component specific UI default values in your application. That should do the trick for you.

One trick you could do is create a dummy application that uses the Nimbus look and feel, create a JTable , and do something like

System.out.println (myTable.getUI ().getClass ().getName ());

At that point you will know which UI object is used to render the JTable when using the Nimbus LAF. You can use this class name when calling setUI (TableUI) on your JTable :

myTable.setUI (new ui_manager_class_name ());

As others have said, this is hardly something we recommend though. LAF's are usually meant to be used as a whole package rather than a mix of 2-3 LAF's. Your other way out could be to use the MultiLookAndFeel , but I have never used it, so I'm not sure it does fulfill your needs. You should read the associated tutorial if you want to use it correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM