• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Icon display

 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any component in java that knows to display icons in matrix?

somthing like :
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A suggestion:
I Guess you can use GridLayout to do the job eazily if all are icons.
 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Roseanne
When using GridLayout I will have to do the hard work of scaling resizing labeling scrolling etc.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the image looks like each of the icons is in an identically sized space,
which would indicate GridLayout is the LayoutManager required.

if you:
add the icons to JLabels
add the JLabels to a JPanel(GridLayout(rows,columns))
add the JPanel to a JFrame
call pack() on the JFrame (instead of giving it a size)
you should get each of the icons displayed, similar to the image posted.
The 'space' occupied by each icon will equal that of the largest icon.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Dunn:

The 'space' occupied by each icon will equal that of the largest icon.



This wont take care of the scaling problem. If I understand the requirement correctly, all the icons of should be of a similar size which can be less than the size of some icons.

I would go for extending a JPanel, say an IconPanel which accepts an icon in the constructor and override the getPreferredSize() to return the required dimension.
This way instead of setting the grid layout and adding the icons, I would add the IconPanel. This way I will have solved the scaling problem. I will also have the flexibility regarding how to display the Icon, either of a label, button(in case some action needs to be taken on icon selection) or maybe even use the icon as the panel background.

Thus I have a parent panel which has a grid layout to which I have added various IconPanels. I noticed a JScrollBar in the original image. So while adding the parent panel I will have to use something like superParentContainer.add(new JScrollPane(parentPanel));
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from the pic, the icons in the middle of the first 2 rows standout as not
being the same size as the rest.

they just seem to be the equivalent of JLabels with icons at their normal size
(no scaling) with text centered/below.

the size of each JLabel would then equal the size of the largest icon (with text).
 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Icons may be in different sizes, but each icon occupy the same space,
That is Frame width / number of horizontal icons
Frame height / number of vertical icons
 
Paddy spent all of his days in the O'Furniture back yard with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic