Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set font for a tab title in jtabbedpane

Tags:

java

fonts

swing

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:

enter image description here

I am create a JPanel (i.e. 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.
like image 276
Hosein Aqajani Avatar asked Oct 31 '25 15:10

Hosein Aqajani


1 Answers

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 ) );
like image 168
Hemang Rindani Avatar answered Nov 02 '25 06:11

Hemang Rindani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!