When using JBTabbedPanel, if the tab's count exceeds one, then switches to the second page, the style of the tab becomes chaotic

已回答

Hello,

I am developing a plugin that uses JBTabbedPanel. My requirement is to add a close button on JBTabbedPanel, as shown in this screenshot(sorry, i cannot upload image, so i put it on gitub, and past the url), the following two both meet my requirement:

https://github.com/hjl-temp-test/ui-demo/blob/main/images/expectedUI.png

or 

https://github.com/hjl-temp-test/ui-demo/blob/main/images/expectedUI2.png

 

I have encountered a problem. When using JBTabbedPanel, if there is more than one tab, switches to the second tab(or other tab that not the first tab), the style of the tab becomes chaotic. Just like what this picture shows:

https://github.com/hjl-temp-test/ui-demo/blob/main/images/demo-reproduce-issue-secondPage-chaotic.png

 

I wrote a simpler demo program to reproduce this issue:

https://github.com/hjl-temp-test/ui-demo

 

repro step:

1. open the plugin project

2.run the plugin from ide: Gradle → intellij → runide → click “ui-test-demo” on the bottom of IDEA:

    on this step, the toolwindow will show the first page of the JBTabbedPanel.

3. click the “Pull down arrow” on Top right corner of  “ui-test-demo” window

   on this step, the toolwindow will show the second page of the JBTabbedPanel

4. on the secon page, the tab of JBTabbedPanel becomes chaotic, Just like what this picture shows:

https://github.com/hjl-temp-test/ui-demo/blob/main/images/demo-reproduce-issue-secondPage-chaotic.png

 

I am not sure if there are other better ways to achieve it,  Or is there something wrong with code when I'm using JBTabbedPanel, such as whether there is something about configuration error.

Could anyone can give me some advice to solve this problem please, Thanks in advance~~

 

0
正式评论

Hello! `JBTabbedPane` should be used only in a very simple cases. In your case I recommend using tab components based on `JBTabsImpl`. You can create one by using `com.intellij.ui.tabs.JBTabsFactory`.

To add a tab, you will need to create an instance of `com.intellij.ui.tabs.TabInfo` - the model of the tab. Then you can add a cancel button to the tab by providing an `ActionGroup` with your own implementation of `AnAction` that closes the tab, to the `com.intellij.ui.tabs.TabInfo#setTabLabelActions`.

Hello,  Konstantin Hudyakov

   Thank you very much. I've managed to solve the problem using an alternative approach by extending BasicTabbedPaneUI. I believe your suggestion might offer another excellent solution, and I intend to give it a try. Should I run into any further issues, I will certainly return for more advice. Once again, thank you for your valuable input~

0

请先登录再写评论。