我的应用程序中有一个JWindow,它在右上角弹出。我已经将形状设置为RoundRectangle2D,但是JWindow的边框没有抗锯齿,因此看起来很糟糕。所以我的问题是,如何消除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);
}}
发布于 2013-07-04 20:04:02
为此,我将展示如何制作具有抗锯齿效果的任意形状的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方法中使用以下方法绘制所需的shpae
public void PaintPanel(Graphics g,Shape PaintArea)
{
Graphics2D gg = (Graphics2D) g;
gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gg.fill(PaintArea);
} https://stackoverflow.com/questions/15407622
复制相似问题