这是 Swing Java 7 渲染错误吗?
我制作了一个简单的 Swing 应用程序。但渲染行为有问题。我做错了什么或者这是一个错误吗?
它是一个简单的小型 JFrame,带有文本字段、按钮和空列表。如果我首先水平调整窗口大小,然后在文本字段中键入内容,该按钮会突然消失。
这是我的代码:
public class App extends JFrame {
public App() {
JTextField messageFld = new JTextField();
JButton saveBtn = new JButton("Save");
JPanel inputPanel = new JPanel(new BorderLayout());
inputPanel.add(messageFld, BorderLayout.CENTER);
inputPanel.add(saveBtn, BorderLayout.EAST);
JList<Data> list = new JList<Data>();
JPanel panel = new JPanel(new BorderLayout());
panel.add(inputPanel, BorderLayout.NORTH);
panel.add(list, BorderLayout.CENTER);
this.getContentPane().add(panel);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Test application");
this.pack();
this.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new App();
}
});
}
}
以下是一些屏幕截图:
启动时
水平调整大小后
在文本字段中输入一些字符后
将鼠标移到按钮上后
我使用 Windows 7、Java 1.7.0 和 Eclipse Indigo SR1。 我使用 JDK 1.7.0.0,现在已升级到 JDK 1.7.0.10,但仍然遇到同样的问题。
当我打印系统属性时,我得到以下结果:
System.out.println(System.getProperty("java.version"));
System.out.println(System.getProperty("java.runtime.version"));
> 1.7.0_01
> 1.7.0_01-b08
I made a simple Swing application. But the rendering behaves buggy. Have I done anything wrong or is it a bug?
It's simple a small JFrame with a textfield, button and an empty list. If I first resizes the window horizontally and then type in the textfield, the button suddenly disappear.
Here is my code:
public class App extends JFrame {
public App() {
JTextField messageFld = new JTextField();
JButton saveBtn = new JButton("Save");
JPanel inputPanel = new JPanel(new BorderLayout());
inputPanel.add(messageFld, BorderLayout.CENTER);
inputPanel.add(saveBtn, BorderLayout.EAST);
JList<Data> list = new JList<Data>();
JPanel panel = new JPanel(new BorderLayout());
panel.add(inputPanel, BorderLayout.NORTH);
panel.add(list, BorderLayout.CENTER);
this.getContentPane().add(panel);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Test application");
this.pack();
this.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new App();
}
});
}
}
Here are a few screenshots:
At start up
After horizontal resize
After typig a few charachers in the textfield
After moving the mouse over the button
I use Windows 7, Java 1.7.0 and Eclipse Indigo SR1.
I used JDK 1.7.0.0 and have now upgraded to JDK 1.7.0.10 but I still have the same problem.
When I print the system properties I get this result:
System.out.println(System.getProperty("java.version"));
System.out.println(System.getProperty("java.runtime.version"));
> 1.7.0_01
> 1.7.0_01-b08
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果问题是由图形驱动程序引起的,设置以下系统属性之一可能会有所帮助。不太确定 Java 7 是否仍然支持这些 props。
In case the issue is caused by your graphics driver, setting one of the system properties below could help. Not quite sure if the props are still supported in Java 7.
我正在使用 eclipse helios 服务版本 2 和 java 1.6,但我没有遇到该错误;它对我来说效果很好。但是它不会让我向 JList 添加参数...这可能是因为我使用的是旧版本的 java...所以基本上在我的设置和 JList 没有参数的情况下它可以工作...我不确定这是否有效会对你有帮助,但这些是我的观察
I am using eclipse helios service release 2, and java 1.6 and I am not getting that bug; it works fine for me. However it wont let me add parameters to JList...that may be because I'm using an older version of java...so basically with my setup and no parameters for JList it works...I'm not sure if this will help you, but those are my observations