Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this a Swing Java 7 rendering bug?

Tags:

java

java-7

swing

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:

  1. At start up

    enter image description here

  2. After horizontal resize

    enter image description here

  3. After typig a few charachers in the textfield

    enter image description here

  4. After moving the mouse over the button

    enter image description here

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
like image 504
Jonas Avatar asked Nov 10 '11 15:11

Jonas


People also ask

Is Java Swing still alive?

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.

What is replacing Java Swing?

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].

Which version of Java has Swing?

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.

Is Swing good for GUI?

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.


2 Answers

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
like image 51
wzberger Avatar answered Oct 04 '22 15:10

wzberger


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

like image 21
PTBG Avatar answered Oct 04 '22 13:10

PTBG