Hi, everyone i have a problem in displaying Jlabels and Icons in a single JPanel. I have used Gridlayout and tried to display the Icons and JLabels in the JPanel. But using GridLayout the JLabels and Icons get dispersed and not in proper order and also the icon get crop, it does not display properly.
Again i tried GridBagLayout and in that, the space between the Jlabels are not proper. Some have gaps between them and some does not have much gap, means it does not look very nice.

I need to display 5 JLabels in left side and 2 Icons on right side of JPanel and the space between the JLabel must all be same and also the Icons must not be croped. I have used two JPanels in top of the main JPanel for the JLabels and the Icons and it can be displayed properly. But without using two more JPanels, whether there is any other option?

So can you give me some suggestion regarding this....

Thanks in advance.

Recommended Answers

All 5 Replies

5 on one side 2 on the other says "two JPanels" to me.
Having said that, I have yet to find a layout (based on rectangles) that couldn't be done with GridBagLayout. You have total control over every position, size, gap, and inset, which with 7 components to place gives you over 100 settings to fiddle with. Not easy, but very powerful.
Do you intend that the display will ever be resized or executed on a screen with very different resolution? If so, GridBagLayout will keep it looking good (if you set all the options right... :) ). If you are absolutely certain you don't need that, then consider going with a null layout manager and positioning everything by pixel address.
But me, I'd use 2 JPanels.

Sir, thank you for you reply. But i want to know 1 thing that if i use too many JPanels then whether it gives trouble in displaying. I mean to say that if using too many JPanels whether it takes time to display.

please let me know.

Thank you.

There's no problem having a few JPanels. It's a perfectly normal thing to do. Maybe hundreds would slow you down, but two or three (or ten) is absolutely fine.

Thank you once again Sir. Thanks for your reply....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.