简体   繁体   中英

how to set font for a tab title in jtabbedpane

I have designed a tabbedpane which includes some tabs, is there any way to set a font for the titles of tabs? I have read this useful question however through this approach we can only set the title of border and not the title of a tab.

A simple code to explain my problem:

private  JTabbedPane tabbedPane;
private  JPanel tab1;
private  Jpanel tab2;
...
tabbedPane.insert("title1", icon1, tab1, "tip1", 0);
tabbedPane.insert("title2", icon2, tab2, "tip2", 1);

How can I change the font of "title1" or "title2" ?


Edit:

According to answer of Dear Jay Smith , I realized that this approach is more powerful, however I have some other problem, see this picture please:

在此处输入图片说明

I am create a JPanel (ie called myPanel) for each tab which consist of two JLabel, one for TabIcon and another for TabTitle. finally, I have writed this:

tabbedPane.setTabComponentAt(0, myPanel);

Now, what are problems:

  1. First of all, notice that I am using persian language which is a right to left, so I want to pull icon to the leftmost position and the tabTitle to the rightmost position.
  2. Second, according to the border of first tab, I want that panel fill entire space of tabHeader.

It is too easy my friend. Do the following and you are through.

JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setFont( new Font( "Dialog", Font.BOLD|Font.ITALIC, 24 ) );

You can set any Swing Component as tab in JTabbedPane .

Example of JLabel as tab:

JLabel label = new JLabel("Tab 1");
label.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 24));

JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setTabComponentAt(0, label);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM