I'm trying to create a JPanel that has a line border as well as margin (padding), like this
but I want to do it without the need to nest JPanel with different borders as currently
public class FolderSelect extends JPanel {
public FolderSelect() {
super() ;
BorderLayout bl =new BorderLayout(10,10) ;
JPanel margin = new JPanel(bl) ;
this.setLayout(new BorderLayout());
this.setBorder(BorderFactory.createLineBorder(Color.gray));
margin.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
margin.add(new JLabel("Folder to check..."), BorderLayout.PAGE_START) ;
margin.add(new JTextField("path/to/folder/to/scan"), BorderLayout.CENTER) ;
margin.add(new JButton("..."), BorderLayout.LINE_END) ;
this.add(margin) ;
}
}
Can I set a line border with top, right, bottom and left padding in a single JPanel ?
I actually want to achieve this with JPanel borders without nesting them
I do not wish to paint my custom border, I want to know if SWT allows this without nesting panels
CodePudding user response:
What you are searching for is a simple combination of borders for one component. This is what CompoundBorder was created for.