Java 空订单到底做什么?

Java 空订单到底做什么?,java,swing,border,flowlayout,Java,Swing,Border,Flowlayout,我试图理解java swing代码。我看到其中有一段代码使用了EmptyBorder,但我不明白它在做什么。我试图在不应用EmptyByOrder的情况下对该部分进行注释和运行,但它并没有对我显示出任何区别。还是我只是错过了UI中的一些细微变化 守则: EmptyBorder border1 = new EmptyBorder(3, 0, 6, 550); ..... JLabel pdt = new JLabel(); pdt.setIcon(icon); pdt.setText("blah

我试图理解java swing代码。我看到其中有一段代码使用了EmptyBorder,但我不明白它在做什么。我试图在不应用EmptyByOrder的情况下对该部分进行注释和运行,但它并没有对我显示出任何区别。还是我只是错过了UI中的一些细微变化

守则:

EmptyBorder border1 = new EmptyBorder(3, 0, 6, 550);
.....
JLabel pdt = new JLabel();
pdt.setIcon(icon);
pdt.setText("blah blah");
pdt.setIconTextGap(5);
pdt.setBorder(border1);
....
border1在这里做什么


我可以使用EmptyByOrder来指定FlowLayout中一组控件之间的间距吗?

正如我在评论中提到的,它只是在添加到的组件周围添加了一个透明边框,有时效果可能很难看到,具体取决于您使用的布局管理器,因此我会在flow布局中包含一些正在使用的控件的图片(很容易看到对流布局的影响):

以下是没有添加边框的流程布局:

这里是流程布局,边框的左侧和右侧分别设置为100和300,边框应用于第一个标签。

最后,这里有一些代码供您测试事物是如何变化的:

import java.awt.FlowLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class EmptyBorderShowCase extends JFrame{

private static final long serialVersionUID = 1L;

public EmptyBorderShowCase(){
    JPanel displayPanel = new JPanel(new FlowLayout());
    final int BOTTOM = 0;
    final int LEFT = 100;
    final int RIGHT = 300;
    final int TOP = 0;
    EmptyBorder border1 = new EmptyBorder(TOP, LEFT, BOTTOM,RIGHT );

    JLabel firstLabel = new JLabel("FIRST");
    firstLabel.setBorder(border1);

    JLabel secondLabel = new JLabel("SECOND");

    displayPanel.add(firstLabel);
    displayPanel.add(secondLabel);
    setContentPane(displayPanel);

    pack();
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
}

public static void main(String[]args){
    new EmptyBorderShowCase();
}

}

您是否尝试过签出for
EmptyBoarder
?EmptyBorders顾名思义是一个没有任何内容的边框,基本上它所做的只是在应用到的组件周围添加一个不可见的边框。(1-)
我可以用EmptyBorder在FlowLayout中给出一组控件之间的间距吗?
-这是什么问题?试试看会发生什么!!!非常感谢。这条信息正是我想要的。:)