Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 1.8 borders rendered incorrectly

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

like image 236
gc_ Avatar asked Aug 05 '14 13:08

gc_


People also ask

What is a matte border in Java?

public class MatteBorder extends EmptyBorder. A class which provides a matte-like border of either a solid color or a tiled icon. Warning: Serialized objects of this class will not be compatible with future Swing releases.


1 Answers

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.

like image 98
gc_ Avatar answered Oct 16 '22 02:10

gc_