9

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
Jonas
  • 121,568
  • 97
  • 310
  • 388
  • 1
    weird, can't reproduce (jdk7, vista) – kleopatra Nov 10 '11 at 15:10
  • I also use jdk 1.7.0 and Windows 7 and the "Save" button is always displayed correctly. – toto2 Nov 10 '11 at 15:26
  • unable to reproduce with Eclipse Juno and Java 1.7.0-b147, also tried different L&F (Nimbus, Metal, Motif, Windows) – user85421 Nov 10 '11 at 15:29
  • It's probably a bug from the graphics driver. I have an ATI card and no bug. – toto2 Nov 10 '11 at 15:35
  • +1, it's a bug, for `BorderLayout.EAST` or `BorderLayout.LINE_END`. Placing the component at any other place, won't lead to the problem. So seems like that area is buggy :-) – nIcE cOw Mar 25 '12 at 10:02
  • Exactly the same issue I am facing with JRE 1.7 update 3, as described in [My Question](http://stackoverflow.com/q/9849950/1057230) – nIcE cOw Mar 25 '12 at 11:26

2 Answers2

8

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
William
  • 3,511
  • 27
  • 35
wzberger
  • 923
  • 6
  • 15
  • This solved this specific problem. But I got similar issues again when adding more components. – Jonas Nov 10 '11 at 19:56
  • 2
    Setting -Dsun.java2d.d3d=false for my JVM startup options cleared out a lot of rendering bugs for me: JDK7/Windows7. – John Oct 12 '13 at 04:48
  • @wzberger same issue is now occurring for table components in jdk 1.8 update 31 and 40, tried setting up your suggested system properties but still not working, issue is similar to http://stackoverflow.com/questions/28876538/java-swing-component-rendering-issue-with-java-8-update-31?noredirect=1#comment46015550_28876538 – Jeevanantham Mar 05 '15 at 12:27
1

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

PTBG
  • 585
  • 2
  • 20
  • 46
  • I got the same 'null result' also using Java 1.6. I suspect the OP is best off posting an [SSCCE](http://sscce.org/) that starts the GUI on the EDT and dumps some basic Java version properties to the `System.out`. – Andrew Thompson Nov 10 '11 at 15:23