Java JPanel & JScrollPane

I working on a application that manage image's filters etc.

I want to have scroll bars when the image is to big to be display. I put my customize panel that extend JPanel in a JScrollPane and I add it in my JFrame.

My image is displayed but not the whole image and the scroll bars are not there.

How to get the scroll-bars to appear?

Here is my code :

CustomePanel test = new ImagePanel(new File("test.jpg"));
test.setPreferredSize(new Dimension(400, 400));
JScrollPane tmp = new JScrollPane(test);


It is likely that your initial preferred size does not match that of your Image. Rather than using setPreferredSize, override getPreferredSize to reflect the size of the image in ImagePanel:

public Dimension getPreferredSize() {
   return new Dimension(image.getWidth(this), image.getHeight(this)); 

A JLabel would be a better approach here if the panel is not required as a container.

Need Your Help

Into or vec: converting sequence back to vector in Clojure

vector clojure sequence

I have the following code which increments the first element of every pair in a vector:

Can you use a binary DLL for your own App?

c# windows dll components

Is it possible to copy a DLL from an installed application into your own bin folder, link to it and call functions at runtime, if you know the API? Does the DLL change if you've bought it from the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.