I am working on a program. In one of my panels there is a JLabel
, which you can click and a dialog will open. So far so good, but if I compile my program to a jar and run it, the label is unclickable and all of my events are ignored, no exceptions, nothing.
In my IDE, the label and its Events are fine and all components work properly. My problem is: I don't know how to fix this.
I don't know if should post some code, but i think its not the code which causes the bug. Some ideas?
Here is a abstract form of my code:
public class TaskListPanel extends javax.swing.JPanel {
private javax.swing.JLabel lblAddTask;
/**
* Creates new form TaskListPanel
*/
public TaskListPanel() {
initComponents();
}
private void initComponents() {
lblAddTask.setIcon(new javax.swing.ImageIcon(getClass().getResource("/path/to/my/icon.png"))); // NOI18N
lblAddTask.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
lblAddTaskMouseClicked(evt);
}
public void mouseEntered(java.awt.event.MouseEvent evt) {
lblAddTaskMouseEntered(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
lblAddTaskMouseExited(evt);
}
});
}
//some more methods
private void lblAddTaskMouseEntered(java.awt.event.MouseEvent evt) {
lblAddTask.setIcon(new ImageIcon(getClass().getResource("/path/to/my/iconhighlighted.png/")));
}
private void lblAddTaskMouseExited(java.awt.event.MouseEvent evt) {
lblAddTask.setIcon(new ImageIcon(getClass().getResource("/path/to/my/icon.png/")));
}
private void lblAddTaskMouseClicked(java.awt.event.MouseEvent evt) {
//mydifferentdialog is a custom dialog, it works fine.
mydifferentdialog dialog = new mydifferentdialog();
}
}
None of my lblAddTask Events are activiated. Is it maybe a problem in my IDE (Netbeans) which causes the bug because it compiles my programm wrong to a jar?