簡短的回答是,你不能,至少不能用該版本的addTab
方法。使用特定的addTab
方法添加到JTabbedPane
的任何內容將在選擇其關聯選項卡時獲得所有可用的屏幕空間。
這聽起來像是你想要將多個Component
放在同一個標籤中,或者在該標籤中改變組件的調整行爲。如果是這種情況,則應首先使用panel.add(Component component,Object constraints)
方法將想要顯示的任何組件添加到JPanel
的實例中,然後將該面板添加到JTabbedPane
。
另一種選擇是做這樣的事情:
JTabbedPane tabs = ...
int index = ... //whatever index you're currently at
Object constraints = ...//these are your constraints
JPanel panel = ...//this is the panel you want constraints for
panel.setName("name"); //will be used as the title when added to tabs in next line
tabs.add(panel, constraints, index);
tabs.setToolTipTextAt(index, "this is a tooltip for 'panel'");
絕對不是吸引人的一行代碼會是這樣,但仍然能夠完成任務。
你能詳細說明你想做什麼嗎? – Reimeus