Java标题边框

时间:2015-09-25 15:39:30

标签: java swing

有没有办法在java swing中设置标题边框的标题字体?

    JPanel panelDOB = new JPanel();
    panelDOB.setBorder(new TitledBorder(new LineBorder(new Color(171, 173, 179)), "DATE OF BIRTH", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(109, 109, 109)));
    panelDOB.setBackground(Color.WHITE);
    panelDOB.setFont(new Font("Tw Cen MT", Font.PLAIN, 12));
    sl_panelFac.putConstraint(SpringLayout.NORTH, panelDOB, 6, SpringLayout.SOUTH, txtNationality);
    sl_panelFac.putConstraint(SpringLayout.WEST, panelDOB, 10, SpringLayout.WEST, panelFac);
    sl_panelFac.putConstraint(SpringLayout.SOUTH, panelDOB, 61, SpringLayout.SOUTH, txtNationality);
    sl_panelFac.putConstraint(SpringLayout.EAST, panelDOB, 196, SpringLayout.WEST, panelFac);
    panelFac.add(panelDOB);
    panelDOB.setLayout(new SpringLayout());

1 个答案:

答案 0 :(得分:5)

只需在Java API中查找TitledBorder即可解答。

在那里你会找到两个构造函数(这里是一个),

public TitledBorder(Border border,
                String title,
                int titleJustification,
                int titlePosition,
                Font titleFont)

采用字体以及设置字体的方法

public void setTitleFont(Font titleFont)

或者,BorderFactory中有两种方法可以使用您选择的字体创建TitledBorder,也可以通过Java API获得。

public static TitledBorder createTitledBorder(Border border,
                                          String title,
                                          int titleJustification,
                                          int titlePosition,
                                          Font titleFont)

我很坦率地感到有些惊讶,因为你没有在来到这里之前查看API