JXStatusBar 约束的替换 LayoutManager 或与 JPanel 一起使用的方式
我正在使用 swingx
库,在 Windows 上我现在转向使用 Flatlaf 所有平台上的浅色和深色外观和感觉
这在 MacOS 上看起来很好,但在 Windows 上,状态栏看起来与 Windows 外观和感觉一样,看起来不正确。
是因为我使用的是 swingx JXStatusBar
组件,它具有一些外观和感觉增强功能,包括一些用于背景的 Windows 特定图像,
例如swingx\swingx-core\src\main\resources\org\jdesktop\swingx\plaf\windows\resources\silver-statusbar-left.png
尝试更改组件的背景颜色或我添加到其中的标签没有效果。
因此,我认为最好的办法是不再使用 JXStatusBar
并仅使用 JPanel,但继续使用 JXStatusBar.Constraint
以相同的方式添加组件
component = new JPanel();
.....
JXStatusBar.Constraint c1 = new JXStatusBar.Constraint();
c1.setFixedWidth(100);
component.add(statusLabel, c1);
JXStatusBar.Constraint c2 = new JXStatusBar.Constraint(JXStatusBar.Constraint.ResizeBehavior.FILL);
c2.setFixedWidth(200);
JXStatusBar.Constraint c4 = new JXStatusBar.Constraint(130);
component.add(filesLoadedLabel, c2);
component.add(filesFilteredLabel, c2);
component.add(tagBrowserFilterLabel, c2);
component.add(activeFiltersLabel, c2);
component.add(mbDelayLabel, c4);
component.add(memoryLabel, c4);
但是,如上面的屏幕截图所示,这无法正常工作,可能是因为我使用了错误的 LayoutManager,但我无法弄清楚 LayoutManager JXStatusBar 正在使用什么,我看不到代码中定义的布局管理器。
所以我的问题是:
- 我需要将 JPanel 设置为什么布局管理器才能以相同的方式对齐?
- 我可以使用什么最相似的 LayoutManager 来达到相同的效果?
编辑
好吧,我已经通过从BasicStatusBarUI
破解内部LayoutManager类来让它基本上工作了,但我想我更愿意只使用标准LayoutManager,这可能吗?
I am using swingx
library, on Windows I am now moving towards using the Flatlaf light and dark look and feel on all platforms
This looks fine on MacOS, but on Windows the status bar looks like it did with Windows look and feel and doesn't look right.
It is because I'm using the swingx JXStatusBar
component and this has some look and feel enhancements including some Windows specific images used for the background
e.g. swingx\swingx-core\src\main\resources\org\jdesktop\swingx\plaf\windows\resources\silver-statusbar-left.png
Trying to change the background colour of the component or the labels I add to it has no effect.
So I thought the best thing to do was move away from using JXStatusBar
and just use a JPanel, but continue adding the components in same way using JXStatusBar.Constraint
component = new JPanel();
.....
JXStatusBar.Constraint c1 = new JXStatusBar.Constraint();
c1.setFixedWidth(100);
component.add(statusLabel, c1);
JXStatusBar.Constraint c2 = new JXStatusBar.Constraint(JXStatusBar.Constraint.ResizeBehavior.FILL);
c2.setFixedWidth(200);
JXStatusBar.Constraint c4 = new JXStatusBar.Constraint(130);
component.add(filesLoadedLabel, c2);
component.add(filesFilteredLabel, c2);
component.add(tagBrowserFilterLabel, c2);
component.add(activeFiltersLabel, c2);
component.add(mbDelayLabel, c4);
component.add(memoryLabel, c4);
However as the screenshot above shows this doesnt work properly, probably because Im using the wrong LayoutManager but I cant work out what LayoutManager JXStatusBar is using I cannot see one defined in the code.
So my question is either:
- What Layout Manager do I need to set JPanel to to align same way?
- What is the most similar LayoutManager I can use instead to have the same effect?
Edit
Okay so I have got it basically working by hacking internal LayoutManager class from BasicStatusBarUI
but I think I would prefer to just use a standard LayoutManager, is that possible ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
flatlaf-swingx.jar
添加到您的项目中,然后JXStatusBar
可以与 FlatLaf 配合使用:请参阅SwingX 的 FlatLaf 插件 和
问题 #492
Add
flatlaf-swingx.jar
to your project, thenJXStatusBar
works fine with FlatLaf:See FlatLaf addon for SwingX and
issue #492