Crigges
Crigges

Reputation: 1243

Windows Explorer like swing layout

I want to create some custom filechooser for images with a special format (.blp). Using a library I can load them as BufferedImage objects. Now I want to create a scrollable image preview of these icons just like in Windows explorer: Please don't be confused by my german os ;)

The main issue is that I can't find a suitable solution which allows vertical scrolling, so the amount of images is limited by the window size.

I already took a look at the answers to these questions:

No scrolling support

No image / scrolling support

So any ideas?

Upvotes: 0

Views: 155

Answers (1)

camickr
camickr

Reputation: 324118

the scrollpane needs a custom layout

Yes, it has a layout to support the scrollbars and row and column headers and the viewport.

So i can't use the GridBagLayout or the ColumnsFlowLayout in there

Sure you can because your add your panel to the viewport, so your panel can use any layout you want.

You may want to just use a JList and add it to the viewport as it supports automatic wrapping. Check out the section from the Swing tutorial on How to Use Lists. You can set the JList orientation to horizontal wrapping.

A JList can render Icons by default, so just add Icons to the ListModel. If you want the icons and the names then you will need to create a custom renderer to display both the text and the Icon.

Or you can use a panel with a Wrap Layout. The WrapLayout wrap components horizontally and works dynamically as the frame is resized.

Upvotes: 4

Related Questions