views:

188

answers:

3

I want to create a java application that is the shape of an "L" so that the application only occupies the left and bottom borders of the screen. I also do not want the normal borders and title bar at the top. I've seen other people creating circles and other shapes like that, but no complex shapes. This is for a windows xp computer and will never be on any other os.

So, how would I do this?

+4  A: 

java.awt.Window/javax.swing.JWindow and java.awt.Frame/javax.swing.JFrame with setUndecorated will create frameless windows. You could put two or more together to create an L-shape.

From 6u10, the Sun JRE also has a non-standard API or non-rectangular and transparent windows.

Tom Hawtin - tackline
+2  A: 

I think this should be possible, although you would probably have to be careful about laying out your components. If you look here, and read the Section on setting the shape of a window it says the following "The shape can be any instance of the java.awt.Shape interface". If you then look at the Shape interface, java.awt.Polygon implements that interface. So you should be able to implement a polygon w/ a "L" shape. Give it a shot.

broschb
A: 

Here you go Asa, this is exactly what you need:

import com.sun.awt.AWTUtilities;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.JFrame;

public static void main(String[] args)
{
    // create an undecorated frame
    final JFrame lframe = new JFrame();                
    lframe.setSize(1600, 1200);
    lframe.setUndecorated(true);

    // using component resize allows for precise control
    lframe.addComponentListener(new ComponentAdapter() {
        // polygon points non-inclusive
        // {0,0} {350,0} {350,960} {1600,960} {1600,1200} {0,1200}
        int[] xpoints = {0,350,350,1600,1600,0};
        int[] ypoints = {0,0,960,960,1200,1200};

        @Override
        public void componentResized(ComponentEvent evt)
        {  
            // create the polygon (L-Shape)
            Shape shape = new Polygon(xpoints, ypoints, xpoints.length);

            // set the window shape
            AWTUtilities.setWindowShape(lframe, shape);
        }
    });

    // voila!
    lframe.setVisible(true);
}

reference -> "Setting the Shape of a Window"

RC