问题
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
回答1:
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.
sun.java2d.d3d=false
sun.java2d.ddoffscreen=false
sun.java2d.noddraw=true
回答2:
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
来源:https://stackoverflow.com/questions/8081559/is-this-a-swing-java-7-rendering-bug