[英]how to set font for a tab title in jtabbedpane
我设计了一个包含一些选项卡的选项卡tabbedpane
,是否可以为选项卡标题设置字体? 我已经阅读了这个有用的问题,但是通过这种方法,我们只能设置边框的标题,而不能设置标签的标题。
一个简单的代码来解释我的问题:
private JTabbedPane tabbedPane;
private JPanel tab1;
private Jpanel tab2;
...
tabbedPane.insert("title1", icon1, tab1, "tip1", 0);
tabbedPane.insert("title2", icon2, tab2, "tip2", 1);
如何更改“ title1”或“ title2”的字体?
编辑:
根据Dear Jay Smith
回答,我意识到这种方法更强大,但是我还有其他问题,请查看此图片:
我为每个选项卡创建一个JPanel(即,称为myPanel),其中包括两个JLabel,一个用于TabIcon,另一个用于TabTitle。 最后,我写了这个:
tabbedPane.setTabComponentAt(0, myPanel);
现在,有什么问题:
我的朋友太容易了。 执行以下操作,您就可以完成。
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setFont( new Font( "Dialog", Font.BOLD|Font.ITALIC, 24 ) );
您可以在JTabbedPane
中将任何Swing Component
设置为选项卡。
JLabel
作为选项卡的示例:
JLabel label = new JLabel("Tab 1");
label.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 24));
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setTabComponentAt(0, label);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.