开发者

Displaying JLayeredPane in JScrollPane

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.getPreferr开发者_如何转开发edSize.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


SOLUTION

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜