我试图创建一个JPanel,它既有行边框,也有边距(填充),如下所示

enter image description here

但我想这样做,而不需要像目前那样用不同的边界嵌套JPanel

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) ;
    }
}

我可以在一个JPanel中设置带有上、右、下和左填充的行边框吗?

I actually want to achieve this with JPanel borders without nesting them enter image description here

我不想绘制自定义边框,我想知道SWT是否允许在没有嵌套面板的情况下进行此操作

推荐答案

您要搜索的是一个组件的边框的简单组合.这就是创建CompoundBorder的目的.

Java相关问答推荐

Listview—在Android Java中正确链接项目时出错

inteliJ中是否有一个功能可以自动在块注释中的/*后面添加一个空格?''

Java List with all combinations of 8 booleans

如何调整工作时间日历中的时间

CompleteableFuture是否运行在不同的内核上?

Com.google.firebase.database.DatabaseException:无法将类型为java.lang.Boolean的值转换为字符串.这是关于什么的?

测试何时使用Mockito强制转换对象会导致ClassCastException

如果按钮符合某些期望,如何修改它的文本?

我怎样才能让IntelliJ标记toString()的任何实现?

buildDir:File!&#的getter解决方案是什么?39.被抛弃

无法播放音频:从资源加载库GStreamer-Lite失败

将双倍转换为百分比

除0错误/抱歉我的句子是PT

为了安全起见,有必要复制一份 list 吗?

处理4.3问题:javax.xml.ind包不存在(&Q;).您可能在学习GitHub教程时遗漏了库.&Q

Java CDI:@Singleton@Startup@Inject无法实现接口

org.springframework.web.HttpRequestMethodNotSupportedException:请求方法';帖子';不支持

多线程、并发和睡眠未按预期工作

这是JavaFX SceneBuilder的错误吗?

在输入端没有可行的替代方案'; Select *';