我设计了一个tabbedpane包含一些选项卡的选项卡,有没有办法为选项卡标题设置字体?我已经阅读了这个有用的问题,但是通过这种方法我们只能设置边框的标题而不是选项卡的标题。
一个简单的代码来解释我的问题:
private JTabbedPane tabbedPane;
private JPanel tab1;
private Jpanel tab2;
...
tabbedPane.insert("title1", icon1, tab1, "tip1", 0);
tabbedPane.insert("title2", icon2, tab2, "tip2", 1);
Run Code Online (Sandbox Code Playgroud)
如何更改“title1”或“title2”的字体?
编辑:
根据 Dear 的回答Jay Smith,我意识到这种方法更强大,但是我还有一些其他问题,请看这张图片:
我为每个由两个 JLabel 组成的选项卡创建一个 JPanel(即称为 myPanel),一个用于 TabIcon,另一个用于 TabTitle。最后,我写了这个:
tabbedPane.setTabComponentAt(0, myPanel);
Run Code Online (Sandbox Code Playgroud)
现在,有什么问题:
小智 6
我的朋友太容易了。执行以下操作,您就完成了。
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setFont( new Font( "Dialog", Font.BOLD|Font.ITALIC, 24 ) );
Run Code Online (Sandbox Code Playgroud)