Skip to content
Advertisement

How can I remove border on JLabel?

So I am trying to start a graphics program, where I have a JFrame that holds multiple JPanels. The JPanels need to combine to create 1 image, however when I run my program I see borders around the images. I cannot quite distinguish if the border is caused by the JLabel that holds the image or if it is because of the JPanel or because of the Layout Manager.

How can I remove the border? Would i need to change the layout manager? If so how?

JavaScript

enter image description here

Advertisement

Answer

rootPanel = new JPanel();

By default a JPanel uses a FlowLayout which defaults to allows 5 pixels before/after components. So when you add our image to the panel you will see 5 pixels of space on all sides.

If you don’t want that space then look at the FlowLayout API and create a FlowLayout without spaces between the components and then add that layout to the rootPanel. Something like:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement