Java 1.8 borders rendered incorrectly
Asked Answered
L

1

11

I am experiencing a few problems with the swing borders after upgrading from Java 1.7 to Java 1.8:

On all my buttons, I need a solid background-color and a solid border, so I defined that via UIManager. On Java 1.7 and previous versions everything looks good, but on Java 1.8 the border is all messed up. Also the RadioButton looks very strange and jaggy. CheckBoxes also seem to have a problem.

For demonstration I created a short sample with a few components:

import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.UIManager;

public class CompDemo extends JFrame
{

    public CompDemo()
    {

        setLayout(new FlowLayout());

        add(new JButton("button"));
        add(new JTextField("txt"));
        add(new JComboBox<String>());
        add(new JRadioButton("radio"));
        add(new JToggleButton("toggle"));
        add(new JCheckBox("check"));

        pack();
        setVisible(true);

    }

    public static void main(String[] args)
    {
        UIManager.put("Button.background", Color.LIGHT_GRAY);
        UIManager.put("Button.border", BorderFactory.createCompoundBorder(BorderFactory
            .createLineBorder(Color.RED), BorderFactory.createLineBorder(Color.CYAN)));

        new CompDemo();

    }

}

Here you can see the output with different JDK versions (scaled up to 200 percent without anti aliasing): The first one is Java 7u60 and displays everything correct. On the second picture I circled the differences. The third one is with Java 8u11 and as you can see the borders are quite messed up (and the dropdown arrow looks strange as well).

http://imgur.com/K4df1Lg

I used a cyan LineBorder inside a red LineBorder so you can see the problem more clearly.

My OS is Windows 8 x64, if it matters.

Can anyone tell me why this looks so different on Java 8? Did I miss something or did they really mess up the borders in Java 1.8? Do I have to file a bug report issue? Or are there just a few adjustments to be made to make it look fine again?

Thanks, gc

Leaseback answered 5/8, 2014 at 13:43 Comment(4)
I could not reproduce that with your supplied code with Windows 7 64-bit, compiled with JDK 8u11.Splenomegaly
Looks fine for me too, Win8.1 x64, JDK 8u11Segno
Fine on Win7/64, Java8u??. The classic hint from the service hotline: "Try to switch it off and on agai ... eh... try to update your graphics driver" (worth a try, at least)Babby
Check out Swing rendering appears broken in JDK 1.8, correct in JDK 1.7. Changing the energy controls of the graphics card to maximum performance solved the problem.Sturgeon
L
2

Thanks for your answers.

I made some further tests. On a virtual machine running Win7 and Java 8 it also looked good, also on another one running Win8 and Java 8.

Changing the graphics card to maximum performance also didnt't change anything. But based on that, I did some more research and finally found out the cause of the problem: My notebook (ThinkPad T540p) has 2 graphics cards: an integrated Intel GMA 4600 and an external Nvidia card. It looks like the OS/driver can decide which graphics card to use for which display and even for which applications. Except for 3D applictions i think mostly the Intel card is used - I guess for energy efficiency reasons (even when it doesn't run on battery).

In the Nvidia Control Panel I can configure that an specific app should always use a specific graphics card, so I defined, that Java should always use the Nvidia graphics card, and that seemed to have solved the problem: with the Nvidia card, everything looks good.

Leaseback answered 6/8, 2014 at 10:8 Comment(3)
I have the same problem. I opened the Nvidia control panel, but where can I configure this setting?Austrasia
Here is a screenshot from my MVIDIA control panel (sorry, my OS is in german): i.imgur.com/JRGpKQQ.png ... so I guess at "Manage 3D settings" you have to switch to "Program settings", select your Java-Binary (maybe multiple ones) on "1." and select the "High-performance NVIDIA processor" on "2.". If you don't have the option to select a graphics processor on "2." I guess you are either using a different driver version or you only have a single graphics card or you graphics processors combination doesn't allow this type of switching.Leaseback
I found exactly the same issue, win7 64 bit, i7 with built-in video. I found that the java8 directx mess will simply miscalculate line end position, causig the extra pixels. Note that on java6 we had the same problem between different rendered size of fillRect(0,0,10,10) and drawRect(0,0,10,10). I found the only workaround is to wrap all Graphics2D operations in an adapter, and calculate different end points depending on the java version in use. I had no other choice, since i have a production code and I have to keep it working.Ticktock

© 2022 - 2024 — McMap. All rights reserved.