たとえば、大きな JComponent があるとします。
Dimension componentSize = new Dimension(5000,5000);
そして小さい JScrollPane:
Dimension scrollPaneSize = new Dimension(500,500);
下の図のように、JScrollPane に JComponent の一部を表示したいと考えています。
白い四角形は私の JScrollPane で、現在(x1,y1)から(x2,y2)までの JComponent の一部を表示しています。
それで、私は何を試しましたか:
新しい JComponent を作成しました。
JComponent component = new JComponent(){
protected void paintComponent(Graphics g)
{
// Here I draw a background
}
};
JScrollPane のビューポート ビューとして配置します。
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(component);
次に、JScrollPane を JFrame にアタッチしました。
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.add(scrollPane, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
そして、次の方法で可視領域を変更しようとします:
scrollpane.getViewport().setBounds(x1,y1,500,500)
どうしたの?