I have pretty much copy pasted the code from http://people.apache.org/~clay/batik/svgcanvas.html but the svg that is outputing is blurry. I have used both a fontawesome and a material ui svg but both were blurry. What am i doing wrong? Here is my code:
public class GUI extends JFrame{
public void init(){
initFrame();
CardLayout cl = new CardLayout();
JPanel panel = new JPanel(cl);
panel.add(createHome(), "HOME");
panel.setBackground(new Color(200, 0, 50));
cl.show(panel, "HOME");
add(panel);
setSize(1280, 720);
setVisible(true);
}
private JPanel createHome(){
JPanel p = new JPanel(new BorderLayout());
{
JPanel d = new JPanel(new FlowLayout(FlowLayout.LEFT));
d.setBackground(new Color(0, 0, 0, 0));
p.add(d, BorderLayout.PAGE_START);
JSVGCanvas svg = new JSVGCanvas();
d.setSize(this.getWidth(), 50);
d.add(svg);
String s = new File("images/userIcon3.svg").toURI().toString();
svg.setMySize(new Dimension(200, 200));
svg.setURI(s);
}
p.setBackground(new Color(0, 50, 200));
p.setSize(this.getWidth(), this.getHeight());
return p;
}
private void initFrame(){
int width = 1280, height = 720;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int swidth = screenSize.width, sheight = screenSize.height;
setTitle("Travelling Agency");
setLocation((swidth - width) / 2, (sheight - height) / 2); //Position it in the center
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
}
So with the help from another question of mine (here) I have come to this conclusion.
Due to the fact that I am working on a laptop with 14 inch screen, Windows has a recommendation for scaling my screen to 125% to improve readability.
So with the help from this answer (here) I've set the "High DPI scaling override" to "System" for my java.exe.
But even though it fixed how the svg is displayed, it had problems with the text. So I added the System.setProperty("awt.useSystemAAFontSettings","on");
System.setProperty("swing.aatext", "true");
that @JustanotherJavaprogrammer mentioned in the comments and now everything seems to be fixed.