0

我的应用程序中有一个 JWindow,它会在右上角弹出。我已将形状设置为 RoundRectangle2D,但 thw JWindow 的边框没有抗锯齿,因此看起来很糟糕。所以我的问题是,如何对 JWindow 进行抗锯齿处理?我知道如何使用 Graphics 对形状进行抗锯齿处理,但这不适用于 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);

}

}

4

1 回答 1

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);
}

然后添加一个与Frame大小相同的JPanel,并在其paint方法中使用以下方法绘制您想要的shpae

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

    gg.fill(PaintArea);
}   
于 2013-07-04T12:04:01.860 回答