Monday, February 20, 2012

JTabbedPane: change tab size when change tab title


I have a a JTabbedPane myTab within my JFrame. Its first tab has a title of "old title". I want to change the title dynamically, so I use this code to set:




myTab.setTitleAt(myTab.getSelectedIndex(), "my full new title");



And somehow my new title is longer than my old one. The problem is, the tab size does not change, and it does not display the new title fully, only "my full n...".



And if I click on the tab, suddenly the tab can show full new title.



I already tried this code too, to set the title name:




myTab.setTabComponentAt(myTab.getSelectedIndex(), new JLabel("my full new title"));



This code can help me change the tab size accordingly to the new title. But the cross (x) to close tab is not there anymore.



Does anyone know how to change the tab size when changing tab title, but still keep the close tab option?



Thank you and much appreciate!

No comments:

Post a Comment