leaning java swing 为组件设置边框

import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import java.awt.*;

public class BorderTest {
    private JFrame jf = new JFrame("test border");
    public void init(){
        jf.setLayout(new GridLayout(2,4));

        Border bb = BorderFactory.createBevelBorder(BevelBorder.RAISED, Color.RED, Color.GREEN,Color.BLUE, Color.GRAY);
        jf.add(getPanelWithBorder(bb, "BevelBorder"));





        jf.pack();
        jf.setVisible(true);

    }

    public static void main(String[] args) {
        new BorderTest().init();
    }

    public  JPanel getPanelWithBorder(Border b, String BorderName) {
        var p = new JPanel();
        p.add(new Label(BorderName));
        p.setBorder(b);
        return  p;

    }
}

output:

posted @ 2019-08-02 16:36  嵌入式实操  阅读(1035)  评论(0编辑  收藏  举报