JFileChooser Icons on 2K Displays

Any idea how to make the Java Swing selector look better on 2K displays, where windows have font scaling> 125%?

I use regular code, for example:

JFileChooser fc = new JFileChooser(); if (settings.currentdir != null) fc.setCurrentDirectory(new File(settings.currentdir)); int returnVal = fc.showOpenDialog((Window) holder); if (returnVal == JFileChooser.APPROVE_OPTION) { 

But file selection displays only tiny icons for the listed files and directories. I am using JDK 8. What is going wrong?

PS: The scope of the question is only Windows, not Unixes. Windows has two standard L & Fs, they scale the font. But they do not scale the icons. the application must do this because it can use various raster resources for higher scales. It seems that JFileChooser is not encoded this way.

But it may be that JFileChooser may be instructed to do so. I don’t see the different size of the question and JFileChooser icons for Windows: How to install DPI of Java Swing applications on Windows / Linux? another question is about font size, which is not a problem for JFileChooser on Windows with one of two Windows L & Fs.

+6
source share
1 answer

Just a quick idea when I came across this topic. You can try putting your own set of icons:

 new JFileChooser().setFileView(new FileView() { @Override public Icon getIcon(File f) { return fancy2kIconForExtension(StringUtils.substringAfterLast(".")); } }); 

be careful to load icons from the cache, since this method is called very often from within JFileChooser , otherwise you end up loading the icon all the time.

+1
source

Source: https://habr.com/ru/post/985666/


All Articles