I am writing GUI program in Java.
I have a JPanel
called jpanel1
that I inserted a JSplitpane
(jSplitPane1
) on it. I set right and left components of jSplitPane1
; jpanel2
& jpanel3
. I set a background image on downward panel (jpanel1
) and I want to JSplitPane
and it's right and left components be transparent such that I can see the background image on them. Is this possible in Java? If this is possible can I use that method to transparent JTree
as JSplitpane
?
It depends on the L&F. AquaL&F on MacOS will respect setOpaque(false) but e.g. Nimbus does not seem to care about it. To force a transparent divider you need to override it in the UI definition of the JSplitPane
jSplitPane.setUI(new BasicSplitPaneUI(){
@Override
public BasicSplitPaneDivider createDefaultDivider() {
return new BasicSplitPaneDivider(this){
@Override
public void paint(Graphics g) {
}
};
}
});
A potential disadvantage is that this approach overrides the L&F for this component and thus might take away other L&F theming elements.