Colorize a tab in a JTabbedPane using java swing

后端 未结 4 1116
孤街浪徒
孤街浪徒 2021-01-15 03:24

I am trying to change the background color of my tabs in a JTabbedPane. I tried JTabbedPane.setBackgroudAt(0, Color.GRAY) and JTabbedPane.set

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-15 04:08

    You should consider using a Look and Feel that does what you want, or failing that, changing the default UIManger settings for a JTabbedPane:

    UIManager.put("TabbedPane.background", Color.GRAY);
    

    If you opt for the latter, it must be done before you create your GUI.

    For more on this, please see Rob Camick's excellent blog on the subject: UIManager Defaults.

    Edit: I was wrong. It should be:

    UIManager.put("TabbedPane.unselectedBackground", Color.GRAY);
    

    But note that this may not work with every Look and Feel.

提交回复
热议问题