开发者

L shaped java application window

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 sha开发者_如何学Gopes 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?


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.


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.


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"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜