Glasspane merupakan salah satu keajaiban di swing, karena effect yang ditimbulakan seperti kaca mungkin di package AWT sulit untuk membuat glass seperti ini, andai ada juga mungkin tidak sebaik di swing.
Contoh GlassPane sederhana.
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagLayout;
import javax.swing.JPanel;
/**
*
* @author manjava
*/
public class GlassPane extends JPanel{
private Color color_trans;
public GlassPane(){
setOpaque(false);
color_trans = new Color(255,255,getBackground().getBlue(),20);
this.setBorder(null);
setBackground(Color.BLACK);
}
public GlassPane(GridBagLayout gb){
setLayout(gb);
setOpaque(false);
color_trans = new Color(255,255,getBackground().getBlue(),20);
}
@Override
public void setBackground(Color c){
super.setBackground(c);
color_trans = new Color(getBackground().getRed(),getBackground().getGreen()
,getBackground().getBlue(),20);
repaint();
}
@Override
protected void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D gd = (Graphics2D) g.create();
gd.setColor(color_trans);
gd.fillRect(0, 0, this.getWidth(), this.getHeight());
gd.dispose();
}
}
Tidak ada komentar:
Posting Komentar