简体   繁体   English

在java swing中渲染问题

[英]Rendering issue in java swing

I have a java application with a GUI running in ubuntu 16.04 using jre 1.7 and I got some rendering issues. 我有一个java应用程序,使用jre 1.7在ubuntu 16.04中运行GUI,我遇到了一些渲染问题。 The following code is not the application code but a simple test case. 以下代码不是应用程序代码,而是一个简单的测试用例。

import javax.swing.JComboBox;
import javax.swing.JFrame;

public class Test {


  public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setSize(400,200);

    String[] s = {"test", "of", "rendering"};
    JComboBox<String> cs = new JComboBox<>(s);
    f.add(cs);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);

  }
}

The following images show the problem: I have 3 elements in the JcomboBox, however when I browse (either by the mouse or the keyboard) the display of the elements changes (which should not happen). 下面的图像显示了问题:我在JcomboBox中有3个元素,但是当我浏览(通过鼠标或键盘)时,元素的显示会发生变化(这不应该发生)。 The problem happens also in Jtree elements. 问题也发生在Jtree元素中。 在此输入图像描述

Any thoughts on this one. 对此有任何想法。 Thanks in advance. 提前致谢。

I had the same problem as you, and I managed to get rid of this rather irritating bug by using the Oracle Java JDK 7 instead of OpenJDK 7 which seems to be having the above issue. 我遇到了和你一样的问题,我设法通过使用Oracle Java JDK 7而不是OpenJDK 7来摆脱这个相当恼人的错误,这似乎有上述问题。

For me the issue is notable just by hovering over the different selections in a JComboBox . 对我来说,只需将JComboBox悬停在JComboBox的不同选项上,就会出现问题。 I did not have this problem using Windows so I figured switching versions of the Java JDK could give a different result. 我没有使用Windows的这个问题,所以我认为Java JDK的切换版本可能会给出不同的结果。

The error is probably located somewhere inside the Swing repaint functions in OpenJDK as the repaint seems to be executed in the wrong thread. 该错误可能位于OpenJDK中Swing重绘函数内部的某处,因为重绘似乎是在错误的线程中执行的。 By extending the RepaintManager class overriding the addDirtyRegion(JComponent c, int x, int y, int w, int h) with an added print out of java.awt.EventQueue.isDispatchThread() I could check the thread used during the repaint. 通过扩展RepaintManager类覆盖addDirtyRegion(JComponent c, int x, int y, int w, int h)并添加了java.awt.EventQueue.isDispatchThread()打印,我可以检查重绘期间使用的线程。

The above function returned false multiple times when hovering inside the JComboBox using OpenJDK but true when using the Oracle JDK. 当使用OpenJDK将JComboBox悬停在JComboBox内部时,上述函数多次返回false,但在使用Oracle JDK时为true I hope someone smarter than me can pinpoint the error exactly and report it, as I have not had the time figure it out or to do a source comparison between the JDK implementations. 我希望比我更聪明的人可以准确地指出错误并报告它,因为我没有时间弄清楚它或者在JDK实现之间进行源代码比较。

PS there seems to be an issue installing Oracle JDK 7 at the moment on Ubuntu using APT, so I downloaded the RPM package, converted it to a deb package using alien by using this method - Oracle Java JDK 7 on Ubuntu Linux - Source or RPM Installation PS目前在使用APT的Ubuntu上安装Oracle JDK 7似乎存在问题,因此我下载了RPM包,使用此方法将其转换为使用alien的deb包 - 在Ubuntu Linux上使用Oracle Java JDK 7 - 源或RPM安装

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM