在 JScrollPane 中显示 JLayeredPane
此代码向我显示了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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案
我将波形的 setPreferredSize 更改为 setSize。现在可以了。
SOLUTION
I changed setPreferredSize of waveform to setSize. Now it works.