Java 使用UIManager的标题边框颜色和宽度

Java 使用UIManager的标题边框颜色和宽度,java,swing,border,uimanager,Java,Swing,Border,Uimanager,要更改所有标题边框字体,我使用UIManager: UIManager.put("TitledBorder.font", new Font("Tahoma", Font.BOLD, 11)); 但是,要在TitledBorder.border属性中添加什么内容,以便只更改边框的颜色(甚至宽度) 干杯好吧,您可以在TitledBorder本身中指定任何属性。 下面是一个完全定制的Swing TitleBorder示例: public static void main ( String[] arg

要更改所有标题边框字体,我使用UIManager:

UIManager.put("TitledBorder.font", new Font("Tahoma", Font.BOLD, 11));
但是,要在TitledBorder.border属性中添加什么内容,以便只更改边框的颜色(甚至宽度)


干杯

好吧,您可以在TitledBorder本身中指定任何属性。 下面是一个完全定制的Swing TitleBorder示例:

public static void main ( String[] args )
{
    LineBorder border = new LineBorder ( Color.RED, 3, true );
    TitledBorder tborder = new TitledBorder ( border, "Titled border", TitledBorder.CENTER,
            TitledBorder.DEFAULT_POSITION, new Font ( "Arial", Font.BOLD, 14 ), Color.BLUE );

    JFrame frame = new JFrame ();

    JLabel label = new JLabel ( "Some content label" );
    label.setBorder ( BorderFactory
            .createCompoundBorder ( BorderFactory.createEmptyBorder ( 50, 50, 50, 50 ),
                    BorderFactory.createCompoundBorder ( tborder,
                            BorderFactory.createEmptyBorder ( 15, 15, 15, 15 ) ) ) );
    frame.add ( label );

    frame.pack ();
    frame.setLocationRelativeTo ( null );
    frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
    frame.setVisible ( true );
}

正如使用
UIManager
一次更改所有
标题边框
字体一样,要更改
标题边框
边框,请使用以下功能:

UIManager.put("TitledBorder.border", new LineBorder(new Color(200,200,200), 1));
它会将border属性更改(设置)为在第二个参数中传递的border对象。 所有边框类型(甚至是factory类)说明都可以在此处找到:

此示例传递
LineBorder
对象,该对象按照您的要求在构造函数中获取颜色和宽度