我想创建一个“L”形的java应用程序,这样应用程序只占据屏幕的左边框和下边框。我也不希望顶部有正常的边框和标题栏。我见过其他人创建类似的圆形和其他形状,但没有复杂的形状。这适用于 windows xp 计算机,永远不会在任何其他操作系统上。
那么,我该怎么做呢?
我想创建一个“L”形的java应用程序,这样应用程序只占据屏幕的左边框和下边框。我也不希望顶部有正常的边框和标题栏。我见过其他人创建类似的圆形和其他形状,但没有复杂的形状。这适用于 windows xp 计算机,永远不会在任何其他操作系统上。
那么,我该怎么做呢?
java.awt.Window
/javax.swing.JWindow
和java.awt.Frame
/ javax.swing.JFrame
withsetUndecorated
将创建无框窗口。您可以将两个或更多放在一起以创建 L 形。
从 6u10 开始,Sun JRE 还具有非标准 API 或非矩形和透明窗口。
我认为这应该是可能的,尽管您可能必须小心布置组件。如果你看这里,并阅读关于设置窗口形状的部分,它会说以下“形状可以是 java.awt.Shape 接口的任何实例”。如果您再查看 Shape 接口,java.awt.Polygon 实现了该接口。所以你应该能够实现一个带有“L”形的多边形。试一试。
给你Asa,这正是你需要的:
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);
}