1

i have a java application and i want to create a responsive "grid layout" for images. For example, i have 10 images, each 200px X 200px, current application window width is 1000px, so i want to have 5 images in first row and 5 images in second. If the window resizes to 1200px width, i want to have 6 images in first row and 4 in second....

enter image description here Any ideas how to achieve this, which layout manager should i use?

I have tried gridLayout, and i am computing number of rows and cols during each window resize, but this looks more like workaround than a good solution.

user2054618
  • 55
  • 10
  • 2
    There a lots of possibilities, you could use `GridBagLayout` which should be able to do something like that or Rob's [`WrapLayout`](https://tips4java.wordpress.com/2008/11/06/wrap-layout/) which should be able to do it as well, for [example](http://stackoverflow.com/questions/15961412/add-thumnails-to-spring-layout-like-a-grid/15961424#15961424) - This, of course, assumes you're using Swing :P – MadProgrammer Feb 17 '16 at 23:12
  • This might come handy for follow-up users: You can easily modify Rob's WrapLayout by using the largest components width as width for all other components to achieve a dynamic column layout where components are layouted into dynamic columns. – peq Nov 21 '22 at 13:39

0 Answers0