Hallo zusammen
-
Wenn ich das Fenster vergrössere, dann kommt der Wert der ehemaligen (kleineren) Grösse raus
-
Wenn ich das Fenster verkleinere, dann kommt der Wert der ehemaligen (grösseren) Grösse raus
public Form(final FTPRunnable ftpRunnable) throws Exception
{
imageLabel = new JLabel("");
Form.properties = (System.getProperty("user.dir") + "/settings/settings.ini").replace("\\", "/");
this.propertyMngr = new PropertyMngr();
this.propertyMngr.init(Form.properties, false);
final String host = this.propertyMngr.getString("host").trim();
final String username = this.propertyMngr.getString("username").trim();
final String password = this.propertyMngr.getString("password").trim();
this.ftp = new FileTransferClient();
this.ftp.setRemoteHost(host);
this.ftp.setUserName(username);
this.ftp.setPassword(password);
this.ftpRunnable = ftpRunnable;
this.mainFrame = new JFrame();
final Color bgcolor = new Color(Integer.parseInt("efefef", 16));
this.mainFrame.getContentPane().setBackground(bgcolor);
JLabel imageLabel = this.imageLabel;
this.mainFrame.getContentPane().add(imageLabel, BorderLayout.CENTER);
this.mainFrame.setTitle("Captured image preview");
this.mainFrame.setBounds(100, 100, Form.APP_WIDTH, Form.APP_HEIGHT);
this.mainFrame.setSize(Form.APP_WIDTH, Form.APP_HEIGHT);
this.mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
mainFrame.addWindowStateListener(new WindowStateListener() {
public void windowStateChanged(WindowEvent arg0)
{
windowStateChanged_mainFrame(arg0);
}
});
}
private void windowStateChanged_mainFrame(WindowEvent e)
{
boolean max = false;
boolean min = false;
if ((e.getNewState() & Frame.NORMAL) == Frame.NORMAL)
{
min = !min;
}
if ((e.getNewState() & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH)
{
max = !max;
}
int imageLabelWidth = imageLabel.getWidth();
int imageLabelHeight = imageLabel.getHeight();
if (max && min)
{
System.out.println("Max. window size ... ");
}
else
{
if (!max && min)
{
System.out.println("Smaller than max. window size ... ");
}
}
System.out.println("imageLabelWidth: " + imageLabelWidth + ", imageLabelHeight: " + imageLabelHeight);
final Image image = bufferedImage.getScaledInstance(imageLabelWidth, imageLabelHeight, Image.SCALE_SMOOTH);
final ImageIcon imageIconNew = new ImageIcon(image);
this.imageLabel.setIcon(imageIconNew);
}
(Schräg ist auch, dass beim Vergrössern beide if zutreffen (if ((e.getNewState() ...
), beim Verkleinern aber nur eines. Deshalb mein Gebastel. Scheint aber zu funktionieren.)