Is it possible to have an Opaque Border
Is it possible to have a transparent border? I'm asking because I'm putting a component into one of Hans Mullers wizzzy MultiSplitPanes which in turn is opaque because It's used inside a TabbedPane (XP colours these with a white background gradient .i.e. not dialog grey).
The tree with scrollpane weren't quite centered so a slapped an empty border on it with insets to make it look square, but the border - even empty ones appear opaque when used inside a transparent component?! Anyone seen this before?
nb.I'd guess it would be possible to nest the scrollpane inside yet another transparent panel with a gridbag insets of (2,2,3,2).. but that seems even more of a pain just to shuffle up one pixel.
This should illustrate the problem, you shouldnt see any grey around the tree:
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
publicclass BorderShouldNotBeSeen{
publicstaticvoid main(String[] args){
JFrame frame =new JFrame();
JPanel panel =new JPanel();
frame.getContentPane().add(panel);
// make it really obvious, should see red right up to the darker scrollpane/tree border
frame.getContentPane().setBackground(Color.RED);
panel.setOpaque(false);
// just BorderFactory.createEmptyBorder() didnt cut it.. so then I used..
class MyBorderextends EmptyBorder{
public MyBorder(Insets insets){
super(insets);
}
publicboolean isBorderOpaque(){
// ..guess what it still looks opaque!
returnfalse;
}
}
JScrollPane treePane =new JScrollPane(new JTree());
treePane.setBorder(BorderFactory.createCompoundBorder(
new MyBorder(new Insets(10, 10, 11, 10)), treePane.getBorder()));
panel.add(treePane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
- Richard

