有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Netbeans在JFrame Gui布局中覆盖图像

我试图在netbeans gui布局中覆盖图像,但它似乎不起作用。我在分层窗格上找到了Oracle教程,但没有帮助

在netbeans GUI环境中,如何在JLabel上覆盖图像

代码是

package my.hangman;


public class HangmanUI extends javax.swing.JFrame {

/**
 * Creates new form HangmanUI
 */
public HangmanUI() {
    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() {

    LayeredPane = new javax.swing.JLayeredPane();
    jLabel3 = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setBackground(new java.awt.Color(57, 156, 255));
    setForeground(new java.awt.Color(57, 156, 255));
    setPreferredSize(new java.awt.Dimension(1024, 768));
    setResizable(false);

    LayeredPane.setPreferredSize(new java.awt.Dimension(1024, 768));

    jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/shelf.fw.png"))); // NOI18N

    javax.swing.GroupLayout LayeredPaneLayout = new javax.swing.GroupLayout(LayeredPane);
    LayeredPane.setLayout(LayeredPaneLayout);
    LayeredPaneLayout.setHorizontalGroup(
        LayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(LayeredPaneLayout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jLabel3)
            .addContainerGap(657, Short.MAX_VALUE))
    );
    LayeredPaneLayout.setVerticalGroup(
        LayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(LayeredPaneLayout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jLabel3)
            .addContainerGap(237, Short.MAX_VALUE))
    );
    LayeredPane.setLayer(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(LayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(LayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    );

    pack();
}// </editor-fold>                        

/**
 * @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 http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    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(HangmanUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(HangmanUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(HangmanUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(HangmanUI.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 HangmanUI().setVisible(true);
        }
    });
}

// Variables declaration - do not modify                     
private javax.swing.JLayeredPane LayeredPane;
private javax.swing.JLabel jLabel3;
// End of variables declaration                   

}


共 (0) 个答案