Set the Background Color for JTabbedPane

后端 未结 6 907
傲寒
傲寒 2021-01-06 13:20

I am using Nimbus Look and feel. I needs to change the Background color and foreground color of the tab in JTabbedPane but the color doesn\'t set in JTabbedPane. I tried set

6条回答
  •  余生分开走
    2021-01-06 14:17

    I hate to break it to you, but you're going to have a very hard time getting the foreground and background colors changed. Unlike many basic components (JTextField, JLabel, etc), the JTabbedPane ignores the foreground and background colors when setting up to paint. Instead it allows the UI delegate (as determined by the current Look and Feel) to choose the colors.

    Some Look and Feels allow for color themes (Substance comes to mind), but Nimbus seems to have those color values hard coded into the paint delegates.

    More than likely you'll need to implement your own UI delegate based off of Nimbus's. See here for more information. It's going to be a major pain, so ask yourself how much you want those colors changed.

    Lastly, if anyone tells you to simply subclass JTabbedPane and set the colors in your own "paintComponent" method, ignore it. You then becomes responsible for the painting of the entire component, and will lose any Nimbus-like visual attributes.

提交回复
热议问题