NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

How to add an EmptyBorder to a JPanel?

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
jacoblockard99



Joined: 15 Nov 2016
Posts: 1

PostPosted: Tue Nov 15, 2016 11:07 pm    Post subject: How to add an EmptyBorder to a JPanel? Reply with quote

Hello everyone!
I am trying to design a form for a simple game in the NetBeans GUI Designer, and I need to create space between/around my controls and panels. After doing a little quick research I have determined that the best method to do this is to use on EmptyBorder on the control. It is very simple to do this in the code, but how do I do this in the designer?

Thank you!
Jacob
Back to top
Schade



Joined: 06 Jan 2017
Posts: 6
Location: France

PostPosted: Thu Jan 12, 2017 9:11 am    Post subject: Reply with quote

Hi,
In the editor, select your panel and in the properties panel, clic on the "..." button of border field. Select "Empty border" and change "insets" by clicking again on the "...".
I used often "Compound border" for making insets in a component with border. It's like the previous method but with two borders to define and select empty border for the outside border.

But if you making a game with complex animation, maybe using Swing's component is not a good idea.
Back to top
priya465



Joined: 17 Aug 2017
Posts: 29

PostPosted: Thu Sep 07, 2017 6:34 am    Post subject: Reply with quote

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Main {
public static void main(String[] args) throws Exception {
JLabel label = new JLabel("java2s.com");

JPanel panel = new JPanel();
panel.add(label);
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));


JOptionPane.showMessageDialog(null, panel);

}
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo