최신 Java 9 Early Access 버전을 다운로드하여 설치했으며, 이제는 Windows에서 Java Swing 응용 프로그램이 올바른 크기로 구성 요소를 렌더링하는 것을 알게되어 매우 기쁩니다. 더 이상 HiDPI 디스플레이로 내 고객이 원하는 너비와 높이의 절반으로 내 앱을 사용해야합니다.Java 9에서 HiDPI 디스플레이에서 고해상도 이미지를 사용하는 방법은 무엇입니까?
그러나 Swing 응용 프로그램에서 내 자신의 아이콘이 너비와 높이를 두 배로 조정하여 단순히 들쑥날쑥하게 보이게 만드는 것을 보았습니다.
정상적인 크기 (예 : foobar.png)와 두 배 너비/높이 (예 : [email protected])의 모든 아이콘이 모두 있습니다. 나는 Apple 명명 규칙을 사용합니다.
Java 9에서 이미지의 고해상도 버전을 수동으로 코드하지 않고도 쉽게 찾고 사용하는 방법은 무엇입니까?
코드 샘플은 항상 더 명확하게 질문하므로 Java 9는 다음 코드를 컴파일하고 실행하는 데 사용할 수있는 다중 해상도 아이콘 클래스를 갖고 있습니까?
import javax.swing.*;
public class ScratchSpace {
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame("I work in HiDPI!");
// can I replace the following line with some magical new method that automatically loads the same icon at multiple resolutions
// so that Swing chooses the correct one when rendering, depending on the current scale of the current display?
Icon icon = new IconWithMultipleSizes("foobar.png");
JLabel label = new JLabel("I'm a label with an icon.", icon, SwingConstants.LEFT);
frame.setContentPane(label);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
}
}
그런 수업이 있어야한다고 생각하지만 찾을 수 없습니다.
지금까지 Java 9에서 java.awt.image.MultiResolutionImage라는 클래스를 발견했습니다.이 클래스는 내가 원하는 것을 수행합니다. 나는 그것이 작동하도록하는 방법에 관한 정보를 찾고있다. –