[英]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.