package com.test.ggg.ui;
import lombok.extern.slf4j.Slf4j;
import javax.swing.*;
import java.awt.*;
import java.io.File;
@Slf4j
public class QrCodeImgDialog extends JDialog
{
public QrCodeImgDialog( String title, JFrame parent, String imgPath )
{
super( parent, "", ModalityType.DOCUMENT_MODAL );
setTitle( title );
if( imgPath.isEmpty() )
{
log.error( "QrCodeImgDialog: Image path is empty!" );
return;
}
File file = new File( imgPath );
if( !file.exists() )
{
log.error( "QrCodeImgDialog: given image file not exist!" );
return;
}
//load image
ImageIcon imageIcon = new ImageIcon( imgPath );
imageIcon = new ImageIcon( imageIcon.getImage().getScaledInstance( 500, 500, Image.SCALE_DEFAULT )); //缩放
JLabel labelImg = new JLabel( imageIcon );
this.getContentPane().add( labelImg, BorderLayout.CENTER );
this.setSize( 700, 700 );
this.setLocation( 300, 20 );
this.setResizable( false );
}
public void showDialog()
{
this.setVisible( true );
}
}