gihooh
gihooh

Reputation: 311

Load image to JScrollPane

I'm trying to create a simple map that will create a circle on a certain coordinate. I want to use an image with it's fixed size as the map and add it to a JScrollPane. My problem here is that I dont know how to add a scrollable image.

Upvotes: 1

Views: 4143

Answers (2)

Josh M
Josh M

Reputation: 11947

Add your image to a JLabel, then add that JLabel to your JScrollPane. If the size of the image is greater than the size of your JScrollPane, the scrollbars will appear. For example:

final Image image = ...
final JLabel imageLabel = new JLabel(new ImageIcon(image));
final JScrollPane scroll = new JScrollPane(imageLabel);
container.add(scroll, ...);

Upvotes: 1

user695992
user695992

Reputation:

Well you need a way to display that image. Is the image embedded in a component?

For example you draw the image in a JPanel

The JPanel can then be added to JScrollPane. When you open your window you open it to the size you want and the scrollbars will be there.

Upvotes: 1

Related Questions