Showing posts with label transparent. Show all posts
Showing posts with label transparent. Show all posts

Java : Transparent JTextField

Complete source code below, will show you how to create a transparent text field in Java.

***********************************************************************
COMPLETE SOURCE CODE FOR : TransparentJTextField.java
***********************************************************************


import javax.swing.*;

import java.awt.*;

public class TransparentJTextField
{
public static void main(String[]args)
{
JFrame myFrame=new JFrame("Transparent JTextField");

JTextField test=new JTextField(10);

//MAKE JTextField TRANSPARENT
test.setOpaque(false);

myFrame.setLayout(new FlowLayout());
myFrame.add(test);
myFrame.setSize(400,100);
myFrame.setLocationRelativeTo(null);
myFrame.setVisible(true);
}
}


***********************************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************************

Java transparent splash screen



Sample


**********************************************************************
TRANSPARENT IMAGE THAT WILL BE USE IN SOURCE CODE (batman.png)
**********************************************************************
Note : Make sure batman.png locate at same location with java file below.You can use other location, but for this simple tutorial, we will use same location.





*******************************************************************
COMPLETE SOURCE CODE FOR : TransparentSplashScreen.java
*******************************************************************

import javax.swing.JWindow;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;


public class TransparentSplashScreen extends JWindow
{
//Get transparent image that will be use as splash screen image.
Image bi=Toolkit.getDefaultToolkit().getImage("batman.png");

ImageIcon ii=new ImageIcon(bi);

public TransparentSplashScreen()
{
try
{
setSize(ii.getIconWidth(),ii.getIconHeight());
setLocationRelativeTo(null);
show();
Thread.sleep(10000);
dispose();
JOptionPane.showMessageDialog(null,"This program will exit !!!","<>",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception exception)
{
exception.printStackTrace();
}
}

//Paint transparent image onto JWindow
public void paint(Graphics g)
{
g.drawImage(bi,0,0,this);
}

public static void main(String[]args)
{
TransparentSplashScreen tss=new TransparentSplashScreen();
}
}


*******************************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************************

RELAXING NATURE VIDEO