我将 Synthetica Black Eye LAF ( http://www.jyloo.com/synthetica/ ) 与使用 Java 1.7 的应用程序一起使用。似乎当我启用 Synthetica LAF 时,如果我将屏幕拖到更大的第二台显示器上,并通过双击或单击最大化图标来最大化窗口,则窗口占用的空间与主显示器上的“全屏”尺寸。当我没有启用 LAF 时,它不会这样做。就好像它没有意识到它在哪个屏幕上的尺寸。有什么解决方法吗?
我已经有效地做到了这一点: Java Toolkit Getting Second screen size and java & fullscreen over multiple monitor 这很好,因为现在我可以将首选尺寸设置为较大显示器的尺寸,但这对我的最大化问题没有帮助。
这是我的代码:
package mil.innovation.bewear.maintenance.windows;
import de.javasoft.plaf.synthetica.SyntheticaBlackEyeLookAndFeel;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class Windows {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(new SyntheticaBlackEyeLookAndFeel());
} catch (Exception e) {
System.out.println("Look and feel not started");
}
Dimension dimension;
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices();
GraphicsDevice biggest;
if (devices.length > 1) {
biggest = devices[0];
for (GraphicsDevice device : devices) {
if (device.getDefaultConfiguration().getBounds().getSize().getWidth() > biggest.getDefaultConfiguration().getBounds().getSize().getWidth())
biggest = device;
}
dimension = biggest.getDefaultConfiguration().getBounds().getSize();
} else if (devices.length == 1)
dimension = devices[0].getDefaultConfiguration().getBounds().getSize();
else {
throw new RuntimeException("No Screens detected");
}
String filePath = "C:\\Users\\Bewear2\\IdeaProjects\\bewear_windows\\imgNotFound.png";
JFrame frame = new JFrame("Example");
JLabel lblPicture = new JLabel();
lblPicture.setPreferredSize(dimension);
lblPicture.setSize(dimension);
BufferedImage image;
try {
image = ImageIO.read(new File("imgNotFound.png"));
lblPicture.setIcon(new ImageIcon(image));
}catch (IOException ex) {
System.out.println("Error loading the picture that is supposed to load when loading a picture fails" + ex);
}
try {
image = ImageIO.read(new File(filePath));
Image bufferedImg = image.getScaledInstance(lblPicture.getWidth(), lblPicture.getHeight(), Image.SCALE_SMOOTH);
lblPicture.setIcon(new ImageIcon(bufferedImg));
} catch (IOException ex) {
System.out.println("Error loading picture " + ex);
}
frame.setContentPane(lblPicture);
frame.pack();
frame.setVisible(true);
}
}