57

I have installed IntelliJ IDEA (13.1.1 #IC-135.480) and JDK 1.8.0 (x64) and I generated some GUI with the GUI Form designer.

Then I ran the code and realized that something is not alright.

Here is a Screenshot of my GUI: Buggy Rendering JDK 1.8.0

The rendering of the Font seems to be not OK. Additionally the Button looses its Text, when I move my mouse over it.

So I installed JDK 1.7.0_40 (x64), recompiled the Project and ran it again.

The following Form appears, when i use JDK 1.7: Rendering OK JDB 1.7.0_40

The Rendering seems to be OK and the Button is also OK.

So I installed the newest Graphics and Chipset drivers and much more, but the problem still exists. Have you ever had such problems with Java Swing UIs? Could you help me to fix my problems? Any help would be greatly appreciated.


UPDATE:

I created a small Project with only 1 JTextArea and 1 JButton and i have the same rendering problems.

According to Andrew Thompson i changed the setSize() and I start from EDT. The Example below:

package at.maeh.java.client.simpleTextClient;

import javax.swing.*;
import java.awt.*;

public class SimpleClient extends JFrame {
    private JPanel panel1;
    private JTextArea textArea1 = new JTextArea();
    private JButton button1 = new JButton();

    public SimpleClient() {
        super("SimpleClient");

        // Panel
        panel1 = new JPanel();
        panel1.setLayout(new FlowLayout());

        // BUtton
        button1.setText("TestButton");

        // TextArea
        textArea1.setColumns(40);
        textArea1.setRows(15);

        // Add Components
        panel1.add(textArea1);
        panel1.add(button1);

        // Add to Frame
        this.getContentPane().add(panel1);

        // pack and set Visible
        pack();
        setVisible(true);

        System.out.println("Constructor EDT: " + SwingUtilities.isEventDispatchThread());
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(SimpleClient::new);

        System.out.println("Main EDT: " + SwingUtilities.isEventDispatchThread());
    }
}

The result is a simple JFrame with the Components in it.

SimpleClient -> Screenshot immediately after Start

When I write some Text, or moove my mousePointer over the Button the components get rendered like this (Text: testsentence.123; Button-Label: TestButton)

after writing - or mouse over

duffy356
  • 3,678
  • 3
  • 32
  • 47
  • 3
    Could you create a smaller example and include the necessary code to allow us to test it ourselves? – FThompson Mar 29 '14 at 22:10
  • 1
    Hi, I made a smaller Project with only 1 TextArea and 1 Button and I have the same problems. I zipped it - you can download it from here: https://drive.google.com/file/d/0B4TRtWhseMOdSm1sVHd6eVhfR3M/edit?usp=sharing – duffy356 Mar 29 '14 at 22:33
  • 2
    It would be preferable for you to include the code in the question itself for the ease of all readers. – FThompson Mar 29 '14 at 22:38
  • 2
    @duffy356: I think an [SSCCE](http://www.sscce.org/) is what Vulcan meant, not a zip file containing the whole project. The reason is that then anybody can just copy our code and test it quickly. – Bhesh Gurung Mar 29 '14 at 22:42
  • @BheshGurung I added the sources. – duffy356 Mar 29 '14 at 22:46
  • What version of IntelliJ are you using? – Jeffrey Mar 29 '14 at 22:49
  • I'm using IntelliJ IDEA 13.1.1 (Build #IC-135.480, built on March 21,2014) – duffy356 Mar 29 '14 at 22:52
  • 2
    That rendering is so far off/bad, that I would really hate to blame (an official) JDK 1.8 release itself - there are *many* tests (and beta-testers) for the Java SDKs/REs these days .. what happens when compiling against/using the Java 8 SDK outside of IntelliJ? If that has the same problems then one more variable can be removed and the IntelliJ-IDEA tag (which should really *not* matter) can be removed. Or, if it *is* a problem with the IDEA setup, then that can be explored in more depth. Also, what happens when running *other* Java Swing programs against JRE 8 on that system? – user2864740 Mar 29 '14 at 23:08
  • I tested it in eclipse, same problem -> IntelliJ-IDEA tag removed -> added eclipse test-src – duffy356 Mar 29 '14 at 23:23
  • 1
    Using your last code sample, I don't see anything wrong with Java 8 (using java outside of eclipse - I don't have eclipse). As a side note though, you should not work with Swing components from a non-EDT thread. So change your main to: `SwingUtilities.invokeLater(SimpleTextClient::new);` – assylias Mar 29 '14 at 23:52
  • @assylias I tried the changed main method you advised, but it didn't solve the problem. – duffy356 Mar 30 '14 at 00:27
  • I tested `SimpleTextClient` on eclipse, and it ran fine without any issue on Ubuntu. – Bhesh Gurung Mar 30 '14 at 00:47
  • I installed Netbeans 8 yesterday. The installer looked exactly like this… The application itself did not suffer from such problems. – Holger Apr 02 '14 at 14:42
  • If you get any probems, I hope my solution will help you too. – duffy356 Apr 02 '14 at 21:23
  • 1
    I had this exact problem with all Swing applications, and I solved it by forcing the discrete graphics card to be used for Java instead of the integrated one. This is described in a deleted answer, I've already flagged it for undeletion. – Malcolm Apr 02 '14 at 23:39
  • 1
    ihave this problem too . [enter link description here][1] [1]: http://stackoverflow.com/a/26263438/395093 – DanialAbdi Oct 09 '14 at 12:42
  • Does everyone with this issue have an Intel HD 4000 graphics chip? – Boann Nov 08 '14 at 11:48
  • Interestingly enough I had this issue using JRE 1.7 running a Swing app on Win 8.1 Guest in VMWare. The solution with disabling D3D (http://stackoverflow.com/a/26610279/200872) did it for me. – Michał Drozdowicz Dec 28 '14 at 13:49
  • 1
    Is there an official Oracle bug # for this issue? – D-Klotz Jan 19 '15 at 16:23
  • 1
    Had the same issue, updated my JDK, now its ok. – Stephan Nov 10 '16 at 13:42

8 Answers8

50

For those whose problem has not been solved; try this solution:

Set the global environment variable "J2D_D3D" to "false" inside the OS. According to Sun, this setting is used to turn off the Java 2D system's use of Direct3D in Java 1.4.1_02 and later.

ie: simply create a environmental variable with name "J2D_D3D" and value "false" without the quotes.

this has solved my rendering problems, hope it does yours also.

25mhz
  • 1,052
  • 2
  • 10
  • 14
  • 6
    This did indeed fix my problem, but wow... how can we expect a customer to do this?.. – D-Klotz Nov 07 '14 at 16:13
  • 1
    yes! you are right, We cant expect any customer to do this. there are two solutions as of now, 1) develop our applications/programs using jdk 1.7 2) set the environmental variable during the installation/run time of the program/application. i will post update here if i find any better way to do this. – 25mhz Nov 07 '14 at 17:19
  • 14
    The command line option `-Dsun.java2d.d3d=false` should also work. – Boann Nov 08 '14 at 06:00
  • 2
    This helped me too! I do not do java programming, just using some applets. And I also started to experience this nasty rendering bug after java update. – SergeyS Dec 06 '14 at 18:55
  • This fixed the issue for me in AndroidStudio (IntelliJ) v1.4. (Sept. 28, 2015 release). The blinking I-bar cursor in editor would make characters disappear and at times the cursor did not render at all. Also, I added the environment var and then restarted AndroidStudio. Thanks – raddevus Oct 20 '15 at 12:02
  • 1
    My problem is with Java 1.8 and the FreeMind app. My second monitor is run by a Nvidia card, and when I drag the FreeMind app into the second window, the contents of the window turn black. I added this environment variable as a system variable, rebooted, and my problem is solved. Adding comment here so people can find this solution via Google. – skelliam Jan 09 '18 at 14:43
  • Reboot was required for me. – Lukas Aug 25 '19 at 18:14
13

Finally I found the solution for my problem. I had to change the energy control settings of my NVIDIA GeForce 620M to maximum performance.

duffy356
  • 3,678
  • 3
  • 32
  • 47
  • 19
    This isn't a solution, it's a workaround, since it's not something you want to have to ask end users of an application to do. – Boann Dec 22 '14 at 04:07
  • i thought it was well found though. Even the flag -Dsun.java2d.d3d=false isn't a solution to the actual problem that the d3d implementation is buggy (afaik from relase 6 to 8 already). – Houtman Nov 28 '16 at 12:36
12

You can follow this steps :

  1. Right-click on desktop and click NVIDIA Control Panel
  2. Select 'Manage 3D Settings' in the left pane
  3. Select the "Program Settings" tab in the main window
  4. Click 'Add'
  5. Navigate to your java folder (C:\Program Files\Java\jre1.8.0_20\bin) and select javaw.exe and press 'open'(this step will probably depend on your operating system but should be pretty easy to find)
  6. Where it says 'Select the preferred graphics processor for this program' click the drop-down and choose 'High Performance NVIDIA processor'
  7. Click 'Apply' in the bottom right and you're good to go.
Lord ST
  • 513
  • 7
  • 15
  • As with other similar answers - this absolutely works for me. But we are delivering a client application to customers and have no control over their hardware - how would you want to force these settings on customer machines? – Koenigsberg Jun 07 '21 at 14:38
8

I have exactly the same problem. What I found after duffys quality setting adjustion:

My Notebook runs both an Intel HD 4000 and a NVS 5200M. Running Swing applications with Java 7 is fine on both cards. With Java 8 Swing GUIs rendered by the Intel card (regardless of quality settings) look crumbled (as in duffys Screenshot), using the NVS 5200M they look as they used to.

Could not find anything on the java bug tracker, on the otherhand it is hard to describe this bug.

nbred
  • 130
  • 7
  • I wonder if this is going to be fixed in a newer version of java 8. I have this on my dell laptop which has the intel HD and a NVS as well. :( – D-Klotz Nov 07 '14 at 16:10
2
textArea1.setSize(500, 300);

There is a problem. Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement or sizing of components. To organize the components for a robust GUI, instead use layout managers, or combinations of them1, along with layout padding & borders for white space2.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 3
    Hi, my problems are not the spacing. The Spacing is fine. I think that the rendering problem has something todo with my system. Because it works for other users (see comments above). – duffy356 Mar 30 '14 at 18:36
  • 2
    *"Because it works for other users (see comments above)."* Yes I already saw them. That means nothing, and is in fact, one of the common signs of explicitly setting sizes - works on one machine fine, fails on others. Post code that doesn't set sizes, that uses `pack()` and starts the GUI on the EDT. Otherwise, this Q&A a pointless waste of time. – Andrew Thompson Mar 31 '14 at 05:45
  • 1
    Hi, i updated my question - Now I use pack() and start from EDT, but I have the same problem. – duffy356 Mar 31 '14 at 20:46
  • Check the [bug database](http://bugs.java.com/). If nothing similar, raise a new one. – Andrew Thompson Mar 31 '14 at 20:49
  • 1
    @HovercraftFullOfEels (shrugs) ..Go figure. ;) – Andrew Thompson Feb 18 '15 at 01:18
  • 2
    This answer is not relevant to OP's issue. – minexew Apr 16 '15 at 20:56
2

Dell Vostro 5480 with ubuntu mate 16.04 I had a similar issue. It's fixed changing the Nvidia Driver, using an additional driver.

enter image description here

And select the NVidia Profile. enter image description here

Rafael Gimenes
  • 146
  • 1
  • 5
1

Similar fix to duffy356:

Lenovo T430s running Windows 7 64 bit with NVIDIA NVS 5200M alongside HD 4000. Update to Java 8 update 5 created graphics and button corruption for two Swing apps, jEdit and Freemind.

Using the NVIDIA control panel applet to change the global settings for Power Management Mode to "Prefer maximum performance" looks like it fixed this issue.

Not sure if there is a lurking issue with how the apps set sizes.

Halfabee2
  • 39
  • 3
0

steps:

  1. control panel
  2. system and security
  3. system
  4. Remote settings
  5. Advanced tab
  6. click Environment variables
  7. create a J2D_D3D variable
  8. and set the value to false.

worked for me,....

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
Vishal Patil
  • 381
  • 3
  • 15