我用netbeans在jLabel的icon属性加了图片,如果是本地图片就没有问题!可是放到包里就不行!这要怎么解决呢?我总不能拿到哪都把那张图片放到相应的路径那用吧?如何放到包里也能用呢?…
我用netbeans在jLabel的icon属性加了图片,如果是本地图片就没有问题!可是放到包里就不行!这要怎么解决呢?我总不能拿到哪都把那张图片放到相应的路径那用吧?如何放到包里也能用呢?
代码如下!
/*
* Show1.java
*
* Created on 2008年8月16日, 下午6:48
*/
package com.sun.test;
/**
*
* @author Administrator
*/
public class Show1 extends javax.swing.JFrame {
/** Creates new form Show1 */
public Show1() {
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.
*/
//
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource(“/com/sun/test/houdao.gif”)));
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}//
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Show1().setVisible(true);
}
});
}
// 变量声明 – 不进行修改
private javax.swing.JLabel jLabel1;
// 变量声明结束
}
展开