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:
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.