Last active
December 17, 2015 12:39
-
-
Save Mononofu/5611323 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; //Graphics2D, LinearGradientPaint, Point, Window, Window.Type; | |
import javax.swing.JComponent; | |
import javax.swing.JFrame; | |
import javax.swing.SwingUtilities; | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import javax.imageio.ImageIO; | |
import java.io.IOException; | |
/** | |
* From JavaMagazine May/June 2012 | |
* @author josh | |
*/ | |
public class ShapedWindowDemo { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
//switch to the right thread | |
SwingUtilities.invokeLater(new Runnable() { | |
@Override | |
public void run() { | |
JFrame frame = new JFrame("About box"); | |
//turn of window decorations | |
frame.setUndecorated(true); | |
//turn off the background | |
frame.setBackground(new Color(255,255,255,0)); | |
frame.setContentPane(new AboutComponent()); | |
frame.pack(); | |
//size the window | |
frame.setSize(500, 200); | |
frame.setVisible(true); | |
//center on screen | |
frame.setLocationRelativeTo(null); | |
} | |
} | |
); | |
} | |
private static class AboutComponent extends JComponent { | |
private BufferedImage image; | |
public AboutComponent() { | |
try { | |
image = ImageIO.read(new File("circle.jpg")); | |
} catch (IOException ex) { | |
// handle exception... | |
} | |
} | |
public void paintComponent(Graphics graphics) { | |
Graphics2D g = (Graphics2D) graphics; | |
g.drawImage(image, 0, 0, null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment