2009-10-22 38 views
1

我想創建一個「L」形狀的java應用程序,以便應用程序只佔用屏幕的左邊框和底邊框。我也不希望正常的邊框和標題欄在頂部。我見過其他人創造圓形和其他形狀,但沒有複雜的形狀。這是一個Windows XP電腦,並將永遠不會在任何其他操作系統。L形java應用程序窗口

那麼,我該怎麼做呢?

回答

4

java.awt.Window/javax.swing.JWindowjava.awt.Frame/javax.swing.JFramesetUndecorated將創建無框窗口。您可以將兩個或更多個放在一起以創建一個L形。

從6u10起,Sun JRE還具有非標準API或非矩形和透明窗口。

2

我認爲這應該是可能的,儘管你可能必須小心地佈置你的組件。如果你看看here,並閱讀關於設置窗口形狀的章節,它會說以下「形狀可以是java.awt.Shape接口的任何實例」。如果您再查看Shape接口,則java.awt.Polygon將實現該接口。所以你應該能夠實現一個具有「L」形狀的多邊形。試一試。

1

在這裏你去亞撒,這正是你需要的東西:

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"