Swing透明遇到输入法等于白屏
来源:互联网 发布:阿里云服务器内存监控 编辑:程序博客网 时间:2024/05/03 05:31
JDK1.7仍然存在~~】
// 最简单的方法:禁止使用DirectDraw
System.setProperty("sun.java2d.noddraw", "true"); // 防止激活输入法时白屏
// 或者重写JTextField的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); } }); }}
1 0
- Swing透明遇到输入法等于白屏
- Swing透明和变换
- Swing开发透明窗体
- Swing 透明窗体实现
- Swing 透明窗体实现
- Swing透明和变换
- swing 组件透明
- 透明和不规则 Swing 窗口
- 透明和不规则 Swing 窗口
- 透明和不规则 Swing 窗口
- 关于Swing实现透明窗体
- 透明和不规则 Swing 窗口
- JAVA-SWING:生成透明JTable
- SWING实现窗体透明效果
- SWING透明窗体,颜色渐变。
- 当inpalceedit遇到输入法
- Java 透明和不规则 Swing 窗口
- Swing不规则窗口和窗口透明
- 算法:插入排序
- Web服务(Web Service)概述
- 深入理解 JavaScript 中的 replace 方法
- U-BOOT源码分析及移植
- 阿西莫夫50年前预言,网文网游正媾和——王冠雄
- Swing透明遇到输入法等于白屏
- 拓胜第十五天
- 有关线程的详细分析
- 用GDB调试程序
- PullToRefresh使用详解(二)---重写BaseAdapter实现复杂XML下拉刷新
- 安卓开发者必备的42个链接
- c++中引用用法总结
- Java完全手册笔记3
- CSS解读之border属性的其他用途