Posts Tagged ‘jdk7’

How to Create Translucent and Shaped Windows in java.

September 4, 2011

Hi all,

I am back after a long time. This time I want to tell you all how I set a window as translucent in java. It was a very cumbersome thing to do before recently. From JDK 6 update 10, java has this facility to set the window as translucent  and its very easy.

Recently I did this in one of my projects and wanted to share it with you all.

As of the Java Platform, Standard Edition 6 (Java SE 6) Update 10 release, we can add translucent and shaped windows to our Swing applications.

The translucent and shaped window API was first added to the Java SE 6 Update 10 release as a private API. This functionality was moved to the public AWT package in the JDK 7 release.

Here is an example :

import java.awt.*;
import javax.swing.*;
import static java.awt.GraphicsDevice.WindowTranslucency.*;

public class MyWindow extends JFrame {
    public MyWindow() {
        super("MyWindow");
        setLayout(new GridBagLayout());

        setSize(300,200);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        add(new JButton("Just a Button"));
    }

    public static void main(String[] args) {
        // Determine if the GraphicsDevice supports translucency.
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
 GraphicsDevice gd = ge.getDefaultScreenDevice();

        //If translucent windows aren't supported, exit.
        if (!gd.isWindowTranslucencySupported(TRANSLUCENT)) { 
 System.err.println( "Translucency is not supported"); 
 System.exit(0); 
 }

        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                MyWindow tw = new MyWindow();

		// Set the window to 55% opaque (45% translucent).
                tw.setOpacity(0.55f);

		// Display the window.
		tw.setVisible(true);
	    }
        });
    }
}

To learn more please check this link.

 

Here is how you can select which methods to use according to your JDK version.

 


Regards,
Manohar Bhattarai (मनोहर भट्टराई)
http://about.me/manoharbhattarai
http://www.facebook.com/pages/Manohar-Bhattarai/130973796914160
Blogs:
https://manoharbhattarai.wordpress.com/
http://manoharbhattarai.posterous.com/
http://manoharbhattarai.blogspot.com/
Microblogs:
Twitter :- http://twitter.com/mhrbhattarai
Identi.ca :- http://identi.ca/manoharbhattarai

Java SE 7 is officially here.

July 28, 2011

Hi all,

Java SE 7 is officially released today i.e. July 28, 2011(07.28.2011)! After nearly five years of collaboration within the worldwide Java community, Java Platform, Standard Edition is ready for download! It’s an important step in Java’s evolution.

The major features of Java SE 7 are:
•    Project Coin- many small language changes that add up to a big boost in productivity for developers
•    The Fork/Join Framework –  facilitates parallelism for mulit-core processors
•    The New File System API (NIO.2) – provides the ability to perform many basic file system operations natively
•    InvokeDynamic – makes it easier to run other languages on the JVM

To learn more about these features, you can view the technical presentations from Oracle’s global event on July 7.

Download Java Platform, Standard Edition (Java SE) 7 

Here is my previous blog : https://manoharbhattarai.wordpress.com/2011/07/12/java-7-is-here/


Regards,
Manohar Bhattarai (मनोहर भट्टराई)
http://about.me/manoharbhattarai
http://www.facebook.com/pages/Manohar-Bhattarai/130973796914160
Blogs:
https://manoharbhattarai.wordpress.com/
http://manoharbhattarai.posterous.com/
http://manoharbhattarai.blogspot.com/
Microblogs:
Twitter :- http://twitter.com/mhrbhattarai
Identi.ca :- http://identi.ca/manoharbhattarai

Java 7 is here.

July 12, 2011

Hi all,

Java 7 (codename Dolphin) is an upcoming major update to Java, releasing on July 28, 2011(07.28.2011). The following links might help you know more about Java 7 :

Webcast on Java 7 : http://www.oracle.com/us/corporate/events/java7/index.html

Wiki on Java 7 : http://wikis.sun.com/display/JDK7/Home

Java se 7 : http://jdk7.java.net/

JDK 7 features : http://openjdk.java.net/projects/jdk7/features/

JDK 7 Java Docs : http://download.java.net/jdk7/docs/api/

I am looking forward to it. So stay tuned.


Regards,
Manohar Bhattarai (मनोहर भट्टराई)
http://about.me/manoharbhattarai
http://www.facebook.com/pages/Manohar-Bhattarai/130973796914160
Blogs:
https://manoharbhattarai.wordpress.com/
http://manoharbhattarai.posterous.com/
http://manoharbhattarai.blogspot.com/
Microblogs:
Twitter :- http://twitter.com/mhrbhattarai
Identi.ca :- http://identi.ca/manoharbhattarai