我創建了兩個面板和一個主面板。每個面板都包含一個非常大的圖像,我希望它們都能夠滾動查看圖像的其餘部分。但是,當我在主面板中添加兩塊面板並運行它時,第一塊麪板非常大以至於它覆蓋了第二塊面板。我將如何爲兩個面板實現ScrollPane?使用多個面板滾動窗格
import java.awt.BorderLayout;
import javax.swing.*;
public class BoardFrame extends JFrame {
JPanel mainPanel = new JPanel(new BorderLayout());
JLabel jLabel = new JLabel();
JPanel jPanelNorth = new JPanel();
JScrollPane scrollPane = new JScrollPane();
JLabel jLabel2 = new JLabel();
JPanel jPanelSouth = new JPanel();
JScrollPane scrollPane2 = new JScrollPane();
public BoardFrame() {
jLabel.setIcon(new ImageIcon("an image here"));
jPanelNorth.add(jLabel);
jLabel2.setIcon(new ImageIcon("an image here"));
jPanelSouth.add(jLabel2);
mainPanel.add(jPanelNorth, BorderLayout.NORTH);
mainPanel.add(jPanelSouth, BorderLayout.SOUTH);
add(mainPanel);
//where would I use this?
//scrollPane.setViewportView();
}
}
謝謝你洙多。這正是我想要做的!可以理解和正確的點!再次感謝 :)!! – Jake