アプリケーションで BorderLayout を使用しています。中央に 2 つの JPanel を追加するメイン パネルがあります。そのうちの1つを透明にしたい。私のコードは次のとおりです。
mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(getGraphPaneScrollPane(), BorderLayout.CENTER);
mainPanel.add(getSituationPanel(), BorderLayout.CENTER);
これら 2 つの関数のコードは次のとおりです。
public JScrollPane getGraphPaneScrollPane() {
if (graphPaneScrollPane == null) {
graphPaneScrollPane = new JScrollPane();
graphPaneScrollPane.setViewportView(getGraphEditorPane());
}
return graphPaneScrollPane;
}
private JScrollPane getSituationPanel(){
if(situationPanel == null){
logs.debug("Initializing Situation Panel");
situationPanel = new JScrollPane();
situationLabel = new JLabel("");
situationLabel.setVerticalTextPosition(JLabel.BOTTOM);
situationLabel.setHorizontalTextPosition(JLabel.CENTER);
situationLabel.setVerticalAlignment(JLabel.TOP);
situationLabel.setHorizontalAlignment(JLabel.CENTER);
situationLabel.setBorder(BorderFactory.createTitledBorder(""));
situationLabel.setBackground(Color.WHITE);
situationLabel.setOpaque(true);
situationLabel.setVerticalAlignment(SwingConstants.TOP);
situationPanel.setViewportView(situationLabel);
}
return situationPanel;
}
getGraphPaneScrollPane はノードを描画するために使用するキャンバスであるため、ここで、situationPanel を透明にし、getGraphPaneScrollPane を GUI の上に配置したいと考えています。