javaswingjsplitpane

How to change the color or background color of JSplitPane divider?


I am trying to the set the background color for the JSplitPane divider. I've written the following code, but it doesn't seem to work.

        BasicSplitPaneUI ui = (BasicSplitPaneUI) splitPane.getUI();
        BasicSplitPaneDivider divider = ui.getDivider();
        divider.setBackground(Color.decode("#FFFACD"));

I've even tried the suggestion given here How to set BackGround color to a divider in JSplitPane

Can someone please point out the mistake or let me know any other approach?


Solution

  • This works for me

    BasicSplitPaneDivider divider = (BasicSplitPaneDivider) splitPane.getComponent(2);
    divider.setBackground(Color.black);
    divider.setBorder(null);