Change interpolation method for Java 2D ui scale


This Content is from Stack Overflow. Question asked by Skretzo

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();
        try {
            panel.add(new JLabel(new ImageIcon("/image.png")))));
        } catch (Exception ignore) {

        JFrame frame = new JFrame("GUI with Image");
        frame.setSize(800, 560);

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 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.


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?