总之,我´我试图制作一个程序,模拟流服务接口的分配。该程序创建两个具有相同规格(大小、约束..)的单独jscrollPane,一个用于电影,一个用于系列,每个包含一个jpanel,然后包含其他电影或系列组件。然后,我创建了一个jlayeredpane(不更改其布局),我想在其中添加两个jscrollpane作为单独的层。但是,当将jscrollpane添加到jlayeredpane并运行代码时,jlayeredpane总是显示最后添加的jscrollpane,而不管我在添加时设置了什么索引。
//creates the movie JScrollPane
JScrollPane moviePanel = stuff.showMovies(movieLogic);
//creates the series JScrollPane
JScrollPane seriesPanel = stuff.showSeries(seriesLogic);
//creates a JLayeredPane in which I want to insert the JScrollPanes as layers
layerPanel = new JLayeredPane();
//adds the moviePanel to index 3 and seriesPanel to index 5 in the JLayeredPane
//I´m assuming index 3 is not as deep as index 5, meaning moviePanel should be in the front,
//but I have also tried switching indexes just in case
layerPanel.add(moviePanel, 3);
layerPanel.add(seriesPanel, 5);
//another attempt at getting the moviePanel to the front of the JLayeredPane, but
//seriesPanel still shows up on top
layerPanel.moveToFront(moviePanel);
我错过了什么或做错了什么?
1条答案
按热度按时间yks3o0rb1#
同样,最简单的解决方案可能是使用jlist和swap模型。例如,以下使用两个模型,一个模型在一周的其他日子显示颜色字符串,模型在按钮的动作侦听器中交换: