Ниже приведен фрагмент, где я создаю свой ImageIcon и JLabel:
ImageIcon armorShopIcon = new ImageIcon("/images/armorshop.png", "Armor Shop");
JLabel armorShopLabel = new JLabel("Armor Shop", armorShopIcon, JLabel.CENTER);
object.setArmorImage(armorShopLabel);
Тогда в моем классе объектов у меня есть сеттер:
public void setArmorImage(JLabel label) {
this.jLabel1 = label;
}
Это изображение не отображается, когда я тестирую свое приложение, и мне было интересно, если кто-то может указать на мою ошибку
EDIT
Большая часть исходного кода:
Main:
public class Main extends javax.swing.JFrame {
public Main() {
initComponents();
ImageIcon armorIcon = new ImageIcon("/images/armorshop.png", "Armor Shop");
JLabel armorShopLabel = new JLabel("Armor Shop", armorShopIcon, JLabel.CENTER);
ShopDisplay armorShop = new ShopDisplay();
armorShop.setArmorImage(armorShopLabel);
public initComponents() { /*more generated code here*/ }
}
}
Дисплей:
public class ShopDisplay extends javax.swing.JPanel {
/** Creates new form ShopDisplay */
public ShopDisplay() {
initComponents();
}
//generated by the gui builder
//initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel1.setText("Shop Name");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
add(jLabel1, gridBagConstraints);
}
//Variable declarationg
private javax.swing.JLabel jLabel1;
//Setter for Shop Name
public void setArmorImage(JLabel shopLabel) {
this.jLabel1 = shopLabel;
}
//other setters for
//multiple jLabels
}