Change interpolation method for Java 2D ui scale

Viewed 34

I am using -Dsun.java2d.uiScale=1.5 to resize my application, however I would like to change the default interpolation algorithm to something other than nearest neighbour, if possible.

This is a simplified version of my application:

package com.guiwithimage;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class GuiWithImage {
    public static void main(String[] args) {
        JPanel panel = new JPanel();
        panel.add(new JLabel("Some text that will be resized too"));
        try {
            panel.add(new JLabel(new ImageIcon(ImageIO.read(GuiWithImage.class.getResourceAsStream("/image.png")))));
        } catch (Exception ignore) {
        }

        JFrame frame = new JFrame("GUI with Image");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 560);
        frame.getContentPane().add(panel);
        frame.setVisible(true);
    }
}

which is then ran with the following command:
javaw.exe -Dsun.java2d.uiScale=1.5 -jar GuiWithImage.jar.

In this simplified example you could circumvent a part of the problem by simply resizing the image.png separately, but this is not feasible in my real case scenario where I want all parts of the GUI to be resized at once by Java.

0 Answers
Related