Leave a Gap between Border and JFrame
I have a JPanel
which is set to BorderLayout
开发者_JAVA百科. I have added 2 JPanels
inside this panel, one south and one center. In the center panel, i added a LowerBevelBorder
. I am finding i am not able to leave a gap between the Main frame and the border. How do i do that? This is my panel1.setBorder(BorderFactory.createLoweredBevelBorder());
Use a compound border which allows you to nest borders without having to create containers just for this purpose. The API can help you set this up. e.g.,
int eb = 10;
panel1.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(eb, eb, eb, eb), // outer border
BorderFactory.createLoweredBevelBorder())); // inner border
Note code not tested.
Note also that this depends on what panel1 is. If it's not the BorderLayout main JPanel, then your best bet is to set the Border of the BorderLayout-using JPanel to be an EmptyBorder.
精彩评论