내 JFrame에는 화면 치수보다 폭과 높이가 더 큰 중앙 패널이 있습니다.이 중앙 패널을 JScrollPane 내부에 표시하고 싶습니다. 이제 문제는 수직 스크롤 막대에 나타나지 않습니다. . JScrollPane는 수직이 아닌 수평 위치만을 표시합니다. 다음은 내 JFrame의 코드입니다. JScrollPane 내부의 JPanel : 세로 막대가 나타나지 않습니다.
import java.awt.*;
import javax.swing.*;
public class TestScroll extends JFrame {
public TestScroll() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setSize(screenSize.width,screenSize.height);
getContentPane().setLayout(new BorderLayout());
JPanel centerPanel=new JPanel(new BorderLayout());
centerPanel.setSize(screenSize.width+50,screenSize.height+50);//I want centralPanel to be of more width and height so to test JScollPane
JPanel northPanel = new JPanel();
Dimension d1=centerPanel.getSize();
northPanel.setPreferredSize(new Dimension(d1.width,d1.height/3));
northPanel.setBackground(Color.BLACK);
centerPanel.add(northPanel, BorderLayout.NORTH);
JPanel innerPanel = new JPanel();
//Dimension d1=centerPanel.getSize();
//panel2.setPreferredSize(new Dimension(d1.width,d1.height/2));
innerPanel.setBackground(Color.ORANGE);
centerPanel.add(innerPanel, BorderLayout.CENTER);
JScrollPane pane=new JScrollPane(centerPanel);
pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
getContentPane().add(pane, BorderLayout.CENTER);
this.setVisible(true);
}
public static void main(String[] args) {
new TestScroll();
}
}
친절
가능한 [중복] (http://stackoverflow.com/q/9092198/230513). – trashgod