如何设置不同的外观和效果想要 JTable 吗?
是否可以为特定组件(在我的例子中 JTable
)设置与已使用的不同的 L&F?如果可以的话,该怎么办呢?
编辑:我根据这个 教程。为什么这段代码不起作用?没有失败或异常,但 JTable
仍然相同。
NimbusLookAndFeel nb = new NimbusLookAndFeel();
jTable1.putClientProperty("Windows.Overrides",nb.getDefaults());
jTable1.putClientProperty("Windows.Overrides.InheritDefaults",false);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以参考以下 URL,了解 nimbus 外观的所有 UI 默认值
http://jasperpotts.com /blogfiles/nimbusdefaults/nimbus.html
转到表部分并在应用程序中使用所有这些表组件特定的 UI 默认值。这应该对你有用。
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.
如果您想将 Nimbus L&F 应用于按钮,那么您只需找出负责渲染 Nimbus 按钮的类即可。该过程与您想要应用自己的自定义 L&F 相同,您可以在按钮上设置自己的 UI 类。
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.
您可以做的一个技巧是创建一个使用 Nimbus 外观和感觉的虚拟应用程序,创建一个
JTable
,然后执行类似的操作,此时您将知道哪个 UI 对象用于渲染
使用 Nimbus LAF 时的 JTable。在
JTable
上调用setUI (TableUI)
时,您可以使用这个类名:正如其他人所说,我们不建议这样做。 LAF 通常作为一个整体使用,而不是 2-3 个 LAF 的混合。您的另一种出路可能是使用
MultiLookAndFeel
,但我从未使用过它,所以我不确定它是否能满足您的需求。您应该阅读相关的 教程如果你想正确使用它。One trick you could do is create a dummy application that uses the Nimbus look and feel, create a
JTable
, and do something likeAt 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 callingsetUI (TableUI)
on yourJTable
: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.