Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Icon display  RSS feed

 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any component in java that knows to display icons in matrix?

somthing like :
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • 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.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!