EVALUATION
This is a problem the the orginal design of Swing and how it has been confusing for years. The issue is setOpaque(false) has had a side effect in exiting LAFs which is that of hiding the background which is not really what it is ment for. It is ment to say that the component my have transparent parts and swing should paint the parent component behind it. Nimbus is the first Sun LAF to need transparency in components for rounded corners and outer glow focus. This means that in Nimbus most of the standard components are non-opaque by default. So setting them to non-opaque has no effect. JButton is nice that it has a setContentAreaPainted() method that can be used to turn off background painting but unfortunatly there has been no option for this with other Nimbus components such as JTextField. One workaround has been to set the background color to transparent like new Color(0,0,0,0). We have decided for this issue to make a color which is 100% transparent (eg, Alpha == 0) mean that the background will not be painted at all.
So the solution for this bugs requirement is:
textField.setBorder(BorderFactory.createEmptyBorder());
textField.setBackground(new Color(0,0,0,0));
Which will give you a textfield with no border or background.
|
EVALUATION
It works with the Metal LaF, assigned to the Nimbus owner
import javax.swing.*;
import java.awt.*;
public class bug6687960 {
private static void createGui() {
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new BorderLayout());
panel.setBackground(Color.red);
frame.add(panel);
JEditorPane pane = new JEditorPane();
pane.setOpaque(false);
panel.add(pane);
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
bug6687960.createGui();
}
});
}
}
|