Hi guys,
In the code below, I want the divider to be painted with a custom color such as red or whatever else.
Unfortunatelly, it doesn't.
I have even try to subclass
BasicSplitPaneDivider
and set the background to red. The result is still unsatisfactory.
Doesn't anyone knows how to fix it.
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.Border;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI;
public class Splitter {
private JSplitPane pane;
public Splitter() {
pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false);
setUp();
}
/**
* @return the pane
*/
public JSplitPane getPane() {
return pane;
}
private void setUp() {
JPanel rightPanel = new JPanel();
rightPanel.setBackground(Color.white);
JTextArea area = new JTextArea(40, 50);
area.setText("Blablaghs");
Dimension minimumSize = new Dimension(100, 50);
area.setMinimumSize(minimumSize);
rightPanel.setMinimumSize(minimumSize);
pane.setRightComponent(rightPanel);
pane.setLeftComponent(area);
pane.setBorder(null);
pane.setUI(new BasicSplitPaneUI() {
public BasicSplitPaneDivider createDefaultDivider() {
return new BasicSplitPaneDivider(this) {
public void setBorder(Border b) {
}
@Override
public void paint(Graphics g) {
g.setColor(Color.red);
super.paint(g);
}
};
}
});
}
private static void createAndShow() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
Splitter sp = new Splitter();
JFrame frame = new JFrame("Frame");
frame.getContentPane().add(sp.getPane());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
frame.setVisible(true);
}
public static void main(String[] a) {
createAndShow();
}
}
Regards.
Edmond