Hallo an alle,
ich hoffe euch gehts allen gut
Ich würde gern ein Icon aus einer exe auslesen mithilfe des JfileChooser und sie dann als ausführbarer button sichtbar machen, nur ich weiss leider nicht wie, da meine Java kenntnisse richtung 0 gehen.
Ich habe auch schon mehrere stunden gegooglt. Bin leider nicht zu dem Erfolg gekommen, den ich erziehlen wollte.
Ich "Arbeite" mit netbeans.
Icon aus exe auslesen habe ich bei google gefunden.
Nur da ich leide nicht die Ahnung von JAVA habe, hänge ich an diesem Punkt leider fest.
Mein "lächerlicher" ansatz hierzu wäre
Vielen Dank für jede Hilfe && Durchlesen
- Lg - FunZel
ich hoffe euch gehts allen gut
Ich würde gern ein Icon aus einer exe auslesen mithilfe des JfileChooser und sie dann als ausführbarer button sichtbar machen, nur ich weiss leider nicht wie, da meine Java kenntnisse richtung 0 gehen.
Ich habe auch schon mehrere stunden gegooglt. Bin leider nicht zu dem Erfolg gekommen, den ich erziehlen wollte.
Ich "Arbeite" mit netbeans.
Icon aus exe auslesen habe ich bei google gefunden.
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication17;
import java.io.File;
import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.filechooser.FileSystemView;
/**
*
* @author Funzel
*/
public class NewJFrame extends javax.swing.JFrame {
/**
* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
public static void main(String[] args) {
String s = "C:/Windows/notepad.exe";
File file = new File (s);
// Get metadata and create an icon
Icon icon = FileSystemView.getFileSystemView().getSystemIcon(file);
// show the icon
JLabel ficon = new JLabel(s, icon, SwingConstants.LEFT);
JFrame frame = new JFrame();
frame.getContentPane().add(ficon);
frame.pack();
frame.setVisible(true);
/* java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
*/
}
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify
// End of variables declaration
}
Nur da ich leide nicht die Ahnung von JAVA habe, hänge ich an diesem Punkt leider fest.
Mein "lächerlicher" ansatz hierzu wäre
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication16;
import java.io.File;
import javax.swing.Icon;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.filechooser.FileSystemView;
/**
*
* @author Funzel
*/
public class NewJFrame extends javax.swing.JFrame {
private File file;
private String s;
/**
* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("What ...");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ActionPerformedLink(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(151, 151, 151)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(163, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(68, 68, 68)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(188, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void ActionPerformedLink(java.awt.event.ActionEvent evt) {
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File( System.getProperty("user.home") + "\\Desktop\\" ));
chooser.setDialogTitle("choosertitle");
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setAcceptAllFileFilterUsed(true);
if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION)
{
String s = getName();
File file = new File (s);
// Get metadata and create an icon
Icon icon = FileSystemView.getFileSystemView().getSystemIcon(file);
// show the icon
JLabel ficon = new JLabel(s, icon, SwingConstants.LEFT);
System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : " + chooser.getSelectedFile());
}
else {
System.out.println("No Selection ");
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see [url=http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html]How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)[/url]
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
// End of variables declaration
}
Vielen Dank für jede Hilfe && Durchlesen
- Lg - FunZel