1

此代码向我显示了 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)

我不知道为什么不显示波形(Waveform extends 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
4

1 回答 1

1

解决方案

我将波形的 setPreferredSize 更改为 setSize。现在它起作用了。

于 2011-09-03T07:26:20.777 回答