Draggable Transparent JFrame in JAVA

Here i am going to post about a JFrame that is transparent ,having a close button and is draggable.The JAVA code is given below.

Code:

public class transparentJFrame {
public static void main(String[] args)
{
new transparentJFrame(Date,Head,Detal);
}
public transparentJFrame(String Date,String Head,String Detal)
{

JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),1));
//Change value of '1' above to have diff transparency
((JComponent)frame.getContentPane()).setBorder(
BorderFactory.createMatteBorder( 3, 2, 2, 2, Color.black));
frame.setBounds(100, 50, 500, 400);
frame.getContentPane().setLayout(null);

final JLabel lblX = new JLabel("X");
lblX.setBounds(frame.getWidth()-15,5,15,15);
lblX.setForeground(new Color(255, 255,255));
lblX.setToolTipText("Closern");
lblX.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
frame.dispose();
}
@Override
public void mouseEntered(MouseEvent e) {
lblX.setForeground(new Color(255, 0, 0));
}
public void mouseExited(MouseEvent e) {
lblX.setForeground(new Color(255, 255,255));
}
});
lblX.setFocusable(false);
frame.getContentPane().add(lblX);
frame.setVisible(true);
}
}

Bikash Panda
Catch Me On

Bikash Panda

Blogger / Embedded System Developer at WGLabz
A techie, tinkerer and tech lover, who loves to blog and feels everyone can learn tech provided they have the right attitude towards learning and passion. By profession, I am an IOT developer working in Smart Home/ Smart Grid domain.
Bikash Panda
Catch Me On

Latest posts by Bikash Panda (see all)

Related posts