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

原帖链接

最新文章

  1. 【JAVA多线程问题之死锁】
  2. noip2016题解汇总
  3. css3 绘制优惠券
  4. windows32位下安装mongodb
  5. c# 赋值后最后一项数据部分丢失
  6. 最直接的教你OC中Block的简单使用场景
  7. MFC创建动态链接库DLL并调用方法详解
  8. CocosCreator检测动作执行完毕的方法~之一吧,应该= =
  9. vue中使用video插件vue-video-player
  10. Java虚拟机:内存分配策略
  11. nginx 反向代理时丢失端口的解决方案
  12. 【bzoj1901】dynamic ranking(带修改主席树)
  13. C# 使用NLog记录日志入门操作
  14. DELPHI 数据集在内存中快速查询方法
  15. foxmail占cpu 100%解决办法
  16. L1-005 考试座位号
  17. solr学习二(ExtractingRequestHandler)
  18. 详解ruby的attr_accessor和cattr_accessor
  19. Common administrative commands in Red Hat Enterprise Linux 5, 6, and 7
  20. 微信小程序基于scroll-view实现锚点定位

热门文章

  1. 动态规划----最长公共子序列(C++实现)
  2. 网络协议TCP
  3. js 技巧 (六)JavaScript[对象.属性]集锦
  4. mysql常用命令用法
  5. 每天学点Python之collections
  6. swift -从相册中选择照片并上传
  7. nativeLibraryDirectories=[/data/app/com.lukouapp-1/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libxxxx.so
  8. 九度oj 题目1055:数组逆置
  9. Avito Code Challenge 2018 C
  10. codevs——1742 爬楼梯