J'ai un problème avec l'activation de JInternalFrame. Je dois indiquer un ImageInternalFrame actif (ma classe, c'est à dire JInternalFrame) parce que j'effectuerai certaines opérations dessus. Je ne sais pas comment le résoudre, quelqu'un peut-il m'aider?Swing: comment devenir actif JInternalFrame
Voici mon code:
public class MainFrame extends javax.swing.JFrame {
ArrayList <ImageInternalFrame> imageInternalFrameList = new ArrayList();
private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File f = chooser.getSelectedFile();
String filePath = f.getPath();
BufferedImage bufferedImage;
ImageInternalFrame imageInternalFrame;
String mimetype= new MimetypesFileTypeMap().getContentType(f);
String type = mimetype.split("/")[0];
if(type.equals("image")){
bufferedImage = null;
try {
bufferedImage = ImageIO.read(new File(filePath));
} catch (IOException ex) {
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
}
imageInternalFrame = new ImageInternalFrame(filePath);
imageInternalFrame.setSize(bufferedImage.getWidth(), bufferedImage.getHeight());
imageInternalFrame.setVisible(true);
imageInternalFrame.setLocation(imageInternalFrameList.size() * 25 , imageInternalFrameList.size() * 25);
add(imageInternalFrame);
imageInternalFrameList.add(imageInternalFrame);
}
else{
JOptionPane.showMessageDialog(null, "It's NOT an image");
}}
public class ImageInternalFrame extends javax.swing.JInternalFrame {
public ImageInternalFrame(String imagePath) {
initComponents();
setImage(imagePath);
}
public void setImage(String imagePath){
imageLabel.setIcon(new ImageIcon(imagePath));
imageLabel.paintImmediately(imageLabel.getVisibleRect());
}
}
Veuillez utiliser la mise en forme du code pour les extraits de code et de code, les documents structurés comme HTML/XML ou les entrées/sorties. Pour ce faire, sélectionnez le texte et cliquez sur le bouton «{}» situé en haut du formulaire de publication/modification de message. –