Java Swing - JPanel 的背景
我想设计一个 JPanel
,其颜色编码应如下图所示:
(来源:compendiumblog.com)
如何对 JPanel
的颜色进行编码。我的想法是在主 JPanel 上添加 5 个 JPanel(上面显示的 5 个块)。将每个 JPanel 的背景
设置为浅灰色
。
但是我怎样才能实现如图所示的深色线条呢?
有什么提示或建议吗?
I want to design a JPanel
which should have the color coding as shown in the following diagram:
(source: compendiumblog.com)
How can I code the colors of a JPanel
. What I think is that add 5 JPanel
s (for 5 blocks shown above) on a main JPanel. Set the background
of each JPanel to light Gray
.
But then how can I achieve the dark color lines as shown in the diagram.
Any hints or suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 JTable,然后交替行的颜色。通过这种方式,您可以编写通用 JComponent (AlternatingColorTable) 并像这 4 个面板中的常规 JTable 一样使用它。
也许是这样的:
}
Try using a JTable and then alternating the colors of the row. This way you can write a generic JComponent (AlternatingColorTable) and use it just like a regular JTable in those 4 panels.
Something like this maybe:
}
只需将每个彩色条本身的面板设置为不同的背景颜色即可。不要忘记使用 setOpaque(true) 使面板显式不透明 - 默认情况下,面板在大多数外观和感觉中都是透明的。
关于美学的注释;我会从每组中的第一行以不同的阴影开始。
Just make each of the colored bars themselves panels with a different background color. Don't forget to make the panels explicitly opaque with setOpaque(true) - panels are transparent by default transparent in most look and feels.
A note on aesthetics; I would start with the first line in each group shaded differently.