Home » Java » java – Remove Unexpected border of JTabbedPane-Exceptionshub

java – Remove Unexpected border of JTabbedPane-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment


I am trying to add tabs in a JTabbedPane. It is displaying the below mentioned white borderline which I am not expecting here as Every color is already set to Black except the white color for the text colors. What I might be missing. enter image description here
I am trying to change this class from jitsi project

Here is what I’ve tried so far.
OS: Ubuntu 19.10: Java Version: 1.8.0_242
Windows 10 Pro: Java Version: 1.8.0_241
I am using default look and feel for this Frame whereas, for my manually created design, it is Nimbus.

How to&Answers:

The answer for the question heavily depends on the Look and Feel you’re using for your application. I can’t tell which one you’re using by just looking at the screenshot because you modified it a lot and you’ve left out part of the code in your question that installs it. In case you aren’t installing any specific one – you’re running the default Look and Feel, which might also be different depending on the OS/JDK versions, if I’m not wrong.

So as @sleepToken already said in the comment – do not post random parts of your code or all of the code, instead post an SSCCE. While sometimes you might think it is unnecessary and/or unrelated – in many cases it is not, and it does help whoever will read and try to answer your question to run the code & debug the issue if necessary.

That being said – I can give a general answer to your question: All component are painted by their respective UI implementation (TabbedPaneUI in this particular case) and in some cases parts of the painting code might not be configurable, for instance some colors or other options might be hard-coded. You can simply look into the source code of the particular UI implementation that your application uses, find the painting code that you want to configure and see if it is actually configurable in the first place.

In case your application uses MetalLookAndFeel – the implementation is MetalTabbedPaneUI. From what I can tell by looking at it’s code – it uses colors from TabbedPane.highlight, TabbedPane.borderHightlightColor and TabbedPane.darkShadow UI defaults for the border. Adding custom color for TabbedPane.highlight might fix the issue for you since you didn’t mention that you modified that one in your question.

In case it doesn’t – I once again recommend posting an SSCCE along with your OS type/version in case you’re using a native Look and Feel. Native Look and Feel differs between different JDK versions for different OS version and often uses a highly customized UI implementation that might not be as configurable.