2013-03-14 177 views
0

我有一個的JWindow在我的應用程序,它在右上角彈出。我已經將形狀設置爲RoundRectangle2D,但JWindow的邊界沒有反鋸齒,因此看起來很可怕。所以我的問題是,我如何反別名JWindow?我知道如何用Graphics來反鋸齒形狀,但這對JWindow本身無效,是嗎?無論如何,我怎樣才能反我的JWindow的邊界?抗鋸齒的JWindow(形狀)

代碼:

公共類選擇實現接口{

//Variables 
//Windows 
    static JWindow Frame = new JWindow(); 

    static JWindow[] Label = new JWindow[100]; 

    static Shape Shape; 

    static JWindow ExitWindow = new JWindow(); 

    static JWindow MenuWindowHide = new JWindow(); 

public static void initialize() { 

    //Settings 
    Frame.setBounds(0,0,(int)Utility.getScreenRes().getWidth(),(int)Utility.getScreenRes().getHeight()); 

    Frame.setOpacity(0.4f); 


    ExitWindow.setBounds((int) (Utility.getScreenRes().getWidth() - 40), 25,20,20); 

    ExitWindow.getContentPane().setBackground(Color.DARK_GRAY); 

    ExitWindow.setShape(new RoundRectangle2D.Double(0,0,20,20, 6, 6)); 

    //Post settings 
    Frame.setVisible(true); 

    ExitWindow.setVisible(true); 

} 

}

回答

0

要做到這一點,我將展示如何做一個JFrame任何形狀,抗鋸齒。

public class MainFrame extends JFrame 
{ 

public MainFrame() 
{ 
    setUndecorated(true); 
    setBackground(new Color(0,255,0,0)); 
    setSize(300, 300); 
    add(PaintingSurface); //Where PaintingSurface is JPanel with PaintPanel method below 
    setVisible(true); 
} 

然後添加一個JPanel,其大小爲框架,並在其paint方法繪製你想用下面的方法

public void PaintPanel(Graphics g,Shape PaintArea) 
{ 
    Graphics2D gg = (Graphics2D) g; 
    gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 

    gg.fill(PaintArea); 
} 
的shpae相同