Here you can find the source of setSplitPaneDividerColor(final JSplitPane pane, final Color color)
Parameter | Description |
---|---|
pane | a parameter |
color | a parameter |
public static void setSplitPaneDividerColor(final JSplitPane pane, final Color color)
//package com.java2s; // it under the terms of the GNU General Public License as published by import javax.swing.*; import javax.swing.border.Border; import javax.swing.plaf.SplitPaneUI; import javax.swing.plaf.basic.BasicSplitPaneDivider; import javax.swing.plaf.basic.BasicSplitPaneUI; import java.awt.*; public class Main { /*********************************************************************************************** * Change the colour of a JSplitPane divider. *//from w w w. j a v a2 s .c o m * @param pane * @param color */ public static void setSplitPaneDividerColor(final JSplitPane pane, final Color color) { final SplitPaneUI splitUI; splitUI = pane.getUI(); // Obviously this will not work if the ui doen't extend BasicSplitPaneUI if (splitUI instanceof BasicSplitPaneUI) { //System.out.println("set split colour"); final BasicSplitPaneDivider divider; divider = ((BasicSplitPaneUI) splitUI).getDivider(); if (divider != null) { //System.out.println("got divider"); final Border divBorder; final Border newBorder; final Border colorBorder; divBorder = divider.getBorder(); class FilledBorder implements Border { private Color color; private final Insets NO_INSETS = new Insets(0, 0, 0, 0); final Rectangle r = new Rectangle(); private FilledBorder(final Color bgcolor) { this.color = bgcolor; } /*********************************************************************************** * * @param c * @param g * @param x * @param y * @param width * @param height */ public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) { //System.out.println("paint border in set divider colour"); g.setColor(this.color); g.fillRect(x, y, width, height); if (c instanceof Container) { final Container cont; cont = (Container) c; for (int i = 0, n = cont.getComponentCount(); i < n; i++) { final Component comp; final Graphics tmpg; comp = cont.getComponent(i); comp.getBounds(r); tmpg = g.create(r.x, r.y, r.width, r.height); comp.paint(tmpg); tmpg.dispose(); } } } public Insets getBorderInsets(final Component c) { return NO_INSETS; } public boolean isBorderOpaque() { return true; } } colorBorder = new FilledBorder(color); if (divBorder == null) { //System.out.println("added to null border"); newBorder = colorBorder; } else { //System.out.println("compound border"); newBorder = BorderFactory.createCompoundBorder(divBorder, colorBorder); } //System.out.println("set border on divider"); divider.setBorder(newBorder); } } } }