Swing questions belong in the Swing forum.
Oh hell, I'm feeling generous...
import java.awt.FlowLayout;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JFrame;
public class FilestreamButton extends JButton
{
public FilestreamButton(String label)
{
super(label);
setContentAreaFilled(false);
}
public static void main(String[] args)
{
JButton button = new FilestreamButton("Basingstoke");
JFrame frame = new JFrame();
frame.getContentPane().setBackground(Color.blue);
frame.getContentPane().add(button);
frame.getContentPane().setLayout(new FlowLayout());
frame.setSize(200, 200);
frame.setVisible(true);
}
}
Now throw me some Dukes. Ceci said I have to buy the next round and that yawmark only drinks imported.
I can help, but it depends on what you mean by "transparent".
Do you mean TOTALLY transparent, or slightly transparent, or merely translucent? Do you want the text on the button to be in any way transparent? You really need to be more specific.
Basically, though, the concept is pretty simple. All swing components have several methods that can be overridden by somebody who knows what they are doing, in order to customize their appearances.
Some of these are: paint(), paintComponent(), ComponentUI.paint(), etc.
You need to determine the right place to put the new code. Then you extend the class, and change the transparency of the graphics object passed into the method in question, and then pass control to the super implementation of that method.
There are some traps you need to make sure you avoid, though:
1. If you want transparent components, you MUST have the opaque property of the component set to false. Otherwise, the components beneath your transparent button will never update.
2. When you start messing with a graphics object to create transparency, you need to make sure that you revert your changes to the graphics object when you are finished, because all painting uses the same graphics object -> so if you set your button transparent, and then forget to remove the transparency, all objects drawn after the button will also be drawn transparent.
A word of caution:
This sort of manipulation is not hard, but you NEED to understand the painting model for SWING. There are a few articles hosted by sun that can help you in this respect.
Good Luck!
- Adam