• java7中使用透明时与输入法冲突


    在Stackoverflow的这找到了答案,需要设置一下系统参数:

        static {
            System.setProperty("sun.java2d.noddraw", "true");
            System.setProperty("sun.java2d.d3d", "false");
        }

    另外还有个修改paintComponent的方式:

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import javax.swing.*;
    
    public class Test {
    
        public static class JTextField2 extends JTextField {
            private static final long serialVersionUID = 1L;
            private BufferedImage buffer = null;
    
            @Override public void paintComponent(Graphics g) {
                Component window = this.getTopLevelAncestor();
                if (window instanceof Window && !((Window)window).isOpaque()) {
                    // This is a translucent window, so we need to draw to a buffer
                    // first to work around a bug in the DirectDraw rendering in Swing.
                    int w = this.getWidth();
                    int h = this.getHeight();
                    if (buffer == null || buffer.getWidth() != w || buffer.getHeight() != h) {
                        // Create a new buffer based on the current size.
                        GraphicsConfiguration gc = this.getGraphicsConfiguration();
                        buffer = gc.createCompatibleImage(w, h, BufferedImage.TRANSLUCENT);
                    }
    
                    // Use the super class's paintComponent implementation to draw to
                    // the buffer, then write that buffer to the original Graphics object.
                    Graphics bufferGraphics = buffer.createGraphics();
                    try {
                        super.paintComponent(bufferGraphics);
                    } finally {
                        bufferGraphics.dispose();
                    }
                    g.drawImage(buffer, 0, 0, w, h, 0, 0, w, h, null);
                } else {
                    // This is not a translucent window, so we can call the super class
                    // implementation directly.
                    super.paintComponent(g);
                }        
            }
        }
    
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                @Override public void run() {
                    final JFrame frame = new JFrame();
                    frame.setUndecorated(true);
                    frame.setBackground(new Color(96, 128, 160, 192));
    
                    JTextField textField = new JTextField2();                
                    JButton exitButton = new JButton("Exit");
                    exitButton.addActionListener(new ActionListener() {
                        @Override public void actionPerformed(ActionEvent e) {
                            frame.dispose();
                        }
                    });
    
                    frame.add(exitButton, BorderLayout.PAGE_START);
                    frame.add(textField, BorderLayout.PAGE_END);
    
                    frame.setSize(400, 400);
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    }

    原帖链接

  • 相关阅读:
    ubuntu14.04显卡驱动问题(amd5600k集显7650d)
    win7 ubuntu 14.04双系统安装
    func_num_args, func_get_arg, func_get-args 的区别与用法
    wamp2.5版本64位403forbidden问题
    mysql根据汉字拼音排序查询
    php判断浏览器语言
    php批量下载文件
    php搜索分页
    把ZenCart在线商店搭建到本地
    livezilla账号或密码修改方法
  • 原文地址:https://www.cnblogs.com/TLightSky/p/3442246.html
Copyright © 2020-2023  润新知