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
Swing and AWT will continue to be supported on Java SE 8 through at least March 2025, and on Java SE 11 (18.9 LTS) through at least September 2026.
Hint: Oracle has developed JavaFX to replace both Swing and AWT. Since Java SE 7, update 6 it is bundled with Java SE. "JavaFX is a set of graphics and media packages that enables developers to (...) deploy rich client applications that operate consistently across diverse platforms" [1].
Originally distributed as a separately downloadable library, Swing has been included as part of the Java Standard Edition since release 1.2. The Swing classes and components are contained in the javax.
It is platform independent unlike AWT and has lightweight components. It becomes easier to build applications since we already have GUI components like button, checkbox etc. This is helpful because we do not have to start from the scratch.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With