我想将多个jscrollpane jpanel添加到jscrollpane jpanel
在我想要隐藏它们的5个项目之后。所以我需要滚动才能看到它们。
这可能吗?如果是,我该怎么做?
这是我编写的用于制作布局和testcenario的代码。
这应该可以正常工作。
private void createLayout() {
setLayout(new BorderLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(15, 15, 15, 15);
for (int i = 0; i < subtitles.size() - 1; i++) {
languageSelectionPanel.add(subtitles.get(i), gbc);
}
gbc.gridx = 0;
gbc.gridy = 0;
startPanel.add(languageSelectionPanel, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
startPanel.add(folderSelectedLabel, gbc);
add(startPanel, BorderLayout.PAGE_START);
for (int j = 0; j < 4; j++) {
JPanel subtitlePanel = new JPanel(new BorderLayout());
subtitlePanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
JPanel subtitleHeader = new JPanel();
JPanel subtitlesContent = new JPanel();
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{0, 110, 200, 45, 17};
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0};
gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0};
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
subtitleHeader.setLayout(gridBagLayout);
subtitlesContent.setLayout(gridBagLayout);
JLabel lblImage = new JLabel("Download");
lblImage.setFont(new Font("Tahoma", Font.BOLD, 14));
GridBagConstraints gbc_lblImage = new GridBagConstraints();
gbc_lblImage.insets = new Insets(0, 0, 5, 5);
gbc_lblImage.gridx = 0;
gbc_lblImage.gridy = 0;
subtitleHeader.add(lblImage, gbc_lblImage);
JLabel lblSkills = new JLabel("Skills");
lblSkills.setFont(new Font("Tahoma", Font.BOLD, 14));
GridBagConstraints gbc_lblSkills = new GridBagConstraints();
gbc_lblSkills.gridx = 1;
gbc_lblSkills.insets = new Insets(0, 0, 5, 5);
gbc_lblSkills.gridy = 0;
subtitleHeader.add(lblSkills, gbc_lblSkills);
JLabel lblExp = new JLabel("Exp");
lblExp.setFont(new Font("Tahoma", Font.BOLD, 14));
GridBagConstraints gbc_lblExp = new GridBagConstraints();
gbc_lblExp.insets = new Insets(0, 0, 5, 5);
gbc_lblExp.gridx = 2;
gbc_lblExp.gridy = 0;
subtitleHeader.add(lblExp, gbc_lblExp);
JLabel lblLevel = new JLabel("Level");
lblLevel.setFont(new Font("Tahoma", Font.BOLD, 14));
GridBagConstraints gbc_lblLevel = new GridBagConstraints();
gbc_lblLevel.insets = new Insets(0, 0, 5, 0);
gbc_lblLevel.gridx = 3;
gbc_lblLevel.gridy = 0;
subtitleHeader.add(lblLevel, gbc_lblLevel);
JSeparator separator = new JSeparator();
GridBagConstraints gbc_separator = new GridBagConstraints();
gbc_separator.fill = GridBagConstraints.HORIZONTAL;
gbc_separator.gridwidth = 4;
gbc_separator.insets = new Insets(0, 0, 5, 0);
gbc_separator.gridx = 0;
gbc_separator.gridy = 1;
subtitleHeader.add(separator, gbc_separator);
for (int i = 0; i < 10; i++) {
JLabel label = new JLabel("Dit is nr: " + (i+1));
GridBagConstraints gbc_label = new GridBagConstraints();
gbc_label.insets = new Insets(0, 0, 5, 5);
gbc_label.gridx = 0;
gbc_label.gridy = i;
subtitlesContent.add(label, gbc_label);
JLabel lblNewLabel = new JLabel("Tweede");
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
gbc_lblNewLabel.gridx = 1;
gbc_lblNewLabel.gridy = i;
subtitlesContent.add(lblNewLabel, gbc_lblNewLabel);
JProgressBar progressBar_1 = new JProgressBar();
progressBar_1.setStringPainted(true);
progressBar_1.setString("Testje" + "/");
GridBagConstraints gbc_progressBar_1 = new GridBagConstraints();
gbc_progressBar_1.fill = GridBagConstraints.HORIZONTAL;
gbc_progressBar_1.insets = new Insets(0, 0, 5, 5);
gbc_progressBar_1.gridx = 2;
gbc_progressBar_1.gridy = i;
subtitlesContent.add(progressBar_1, gbc_progressBar_1);
JLabel label_1 = new JLabel("1");
GridBagConstraints gbc_label_1 = new GridBagConstraints();
gbc_label_1.insets = new Insets(0, 0, 5, 0);
gbc_label_1.gridx = 3;
gbc_label_1.gridy = i;
subtitlesContent.add(label_1, gbc_label_1);
}
subtitlePanel.add(subtitleHeader, BorderLayout.PAGE_START);
subtitlePanel.add(subtitlesContent, BorderLayout.CENTER);
centerPanel.add(subtitlePanel, BorderLayout.CENTER);
JScrollPane centerScrollPane = new JScrollPane(centerPanel);
centerScrollPane.setBorder(null);
add(centerScrollPane, BorderLayout.CENTER);
}
}