在 JScrollPane 中显示 JLayeredPane

发布于 2024-12-03 04:09:22 字数 1771 浏览 1 评论 0原文

此代码向我显示了scrollPane 内部的波形:

var scrollPane = new JScrollPane
var waveform = new Waveform(trackModel)   // JPanel with waveform

scrollPane.setViewportView(waveform)

这仅向我显示了scrollPane 中的灰色背景:

var scrollPane = new JScrollPane
var layeredPane = new JLayeredPane
var waveform = new Waveform(trackModel)   // JPanel with waveform

layeredPane.add(waveform, JLayeredPane.DEFAULT_LAYER)
layeredPane.setPreferredSize(trackModel.getSize())
scrollPane.setViewportView(layeredPane)

我不知道为什么不显示波形(波形扩展了JPanel)。这是更多信息:

System.out.println("waveform visibility: " + waveform.isVisible)
System.out.println("layeredPane visibility: " + layeredPane.isVisible)
System.out.println("scrollPane visibility: " + scrollPane.isVisible)

System.out.println("waveform dimensions: " + waveform.getPreferredSize.width + "/" + waveform.getPreferredSize.height)
System.out.println("layeredPane dimensions: " + layeredPane.getPreferredSize.width + "/" + layeredPane.getPreferredSize.height)
System.out.println("scrollPane dimensions: " + scrollPane.getPreferredSize.width + "/" + scrollPane.getPreferredSize.height)

System.out.println("waveform dimensions: " + waveform.getWidth + "/" + waveform.getHeight)
System.out.println("layeredPane dimensions: " + layeredPane.getWidth + "/" + layeredPane.getHeight)
System.out.println("scrollPane dimensions: " + scrollPane.getWidth + "/" + scrollPane.getHeight)

以及输出:

waveform visibility: true
layeredPane visibility: true
scrollPane visibility: true
waveform dimensions: 40315/200
layeredPane dimensions: 40315/200
scrollPane dimensions: 40318/203
waveform dimensions: 0/0
layeredPane dimensions: 0/0
scrollPane dimensions: 0/0

This code shows me waveform inside of scrollPane:

var scrollPane = new JScrollPane
var waveform = new Waveform(trackModel)   // JPanel with waveform

scrollPane.setViewportView(waveform)

And this shows me just a grey background in scrollPane:

var scrollPane = new JScrollPane
var layeredPane = new JLayeredPane
var waveform = new Waveform(trackModel)   // JPanel with waveform

layeredPane.add(waveform, JLayeredPane.DEFAULT_LAYER)
layeredPane.setPreferredSize(trackModel.getSize())
scrollPane.setViewportView(layeredPane)

I don't know why waveform (Waveform extends JPanel) is not displayed. Here is more info:

System.out.println("waveform visibility: " + waveform.isVisible)
System.out.println("layeredPane visibility: " + layeredPane.isVisible)
System.out.println("scrollPane visibility: " + scrollPane.isVisible)

System.out.println("waveform dimensions: " + waveform.getPreferredSize.width + "/" + waveform.getPreferredSize.height)
System.out.println("layeredPane dimensions: " + layeredPane.getPreferredSize.width + "/" + layeredPane.getPreferredSize.height)
System.out.println("scrollPane dimensions: " + scrollPane.getPreferredSize.width + "/" + scrollPane.getPreferredSize.height)

System.out.println("waveform dimensions: " + waveform.getWidth + "/" + waveform.getHeight)
System.out.println("layeredPane dimensions: " + layeredPane.getWidth + "/" + layeredPane.getHeight)
System.out.println("scrollPane dimensions: " + scrollPane.getWidth + "/" + scrollPane.getHeight)

And the output:

waveform visibility: true
layeredPane visibility: true
scrollPane visibility: true
waveform dimensions: 40315/200
layeredPane dimensions: 40315/200
scrollPane dimensions: 40318/203
waveform dimensions: 0/0
layeredPane dimensions: 0/0
scrollPane dimensions: 0/0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情空心 2024-12-10 04:09:22

解决方案

我将波形的 setPreferredSize 更改为 setSize。现在可以了。

SOLUTION

I changed setPreferredSize of waveform to setSize. Now it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文