java7中使用透明时与输入法冲突
2013-11-25 21:29
260 查看
在Stackoverflow的这找到了答案,需要设置一下系统参数:
另外还有个修改paintComponent的方式:
原帖链接
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); } }); } }
原帖链接
相关文章推荐
- 线程中使用ADO 后入输入法冲突解决办法....
- 关于透明状态栏的使用以及与软键盘冲突(导致SrollView不能滑动)的解决办法
- 关于透明状态栏的使用以及与软键盘冲突的解决办法
- eclipse快捷键以及使用技巧大全 (其中shift+ctrl+F 格式化 会和搜狗输入法冲突,把输入法这个关了)
- Linux下Qt4与qt5的程序使用输入法(ibus与fcitx)不冲突
- Gradle依赖项学习总结,dependencies、transitive、force、exclude的使用与依赖冲突解决
- ubuntu8.04 scim 下英文环境中使用中文输入法
- VC++使用CImage PNG转BMP图片透明背景处理
- Qt+VS编译器:默认库“library”与其他库的使用冲突;使用 /NODEFAULTLIB:library
- BREW事件使用技巧: 避免事件冲突
- IE 6 使用 VML 解决png透明问题
- lua中使用packagepath解决多个项目的路径冲突问题
- 在jQuery中使用$而避免跟其它库产生冲突的方法
- 使用hibernate-validator进行验证时与tomcat产生的方法冲突问题【NoSuchMethodError】
- MFC绘图5--使用透明画刷
- CentOS英文环境下使用中文输入法
- Eclipse SVN插件冲突导致不能使用解决办法
- RecyclerView使用案例一之滑动冲突
- [0] 解决版本冲突-使用SVN主干与分支功能
- linux使用flock文件锁解决crontab冲突问题