Netbeans6.9.1 Image as icons
I'm currently using Netbean 6.9.1 and I just want to add some PNG files to my program when it builds. I'm using the files as icons for some of the GUI buttons and labels. But when I select clean and build main project or build main project and execute the J开发者_运维问答AR file outside the IDE, the icons are missing.
I put the image files into my project folder and basically just add this kinda code in. the code is working it sisplays the icons but it did nor pick the images for those icons.
void setMainForm(Resources r) {
UIManager.getInstance().setResourceBundle(r.getL10N("localize", "en"));
MainScreenForm main = new MainScreenForm(this, "Business Organiser");
if(mainMenu != null){
main.setTransitionInAnimator(mainMenu.getTransitionInAnimator());
main.setTransitionOutAnimator(mainMenu.getTransitionOutAnimator());
}else{
main.setTransitionOutAnimator(CommonTransitions.createFade(400));
}
mainMenu = main;
int width = Display.getInstance().getDisplayWidth(); //get the display width
elementWidth = 0;
Image[] selectedImages = new Image[DEMOS.length];
Image[] unselectedImages = new Image[DEMOS.length];
final ButtonActionListener bAListner = new ButtonActionListener();
for (int i = 0; i < DEMOS.length; i++) {
Image temp = r.getImage(DEMOS[i].getName() + "_sel.png");
selectedImages[i] = temp;
unselectedImages[i] = r.getImage(DEMOS[i].getName() + "_unsel.png");
final Button b = new Button(DEMOS[i].getName(), unselectedImages[i]);
b.setUIID("DemoButton");
b.setRolloverIcon(selectedImages[i]);
b.setAlignment(Label.CENTER);
b.setTextPosition(Label.BOTTOM);
mainMenu.addComponent(b);
b.addActionListener(bAListner);
b.addFocusListener(new FocusListener() {
public void focusGained(Component cmp) {
if (componentTransitions != null) {
mainMenu.replace(b, b, componentTransitions);
}
}
public void focusLost(Component cmp) {
}
});
demosHash.put(b, DEMOS[i]);
elementWidth = Math.max(b.getPreferredW(), elementWidth);
}
if(cols == 0){
cols = width / elementWidth;
}
int rows = DEMOS.length / cols;
mainMenu.setLayout(new GridLayout(rows, cols));
mainMenu.setDragMode(true);
mainMenu.addCommand(exitCommand);
mainMenu.addCommand(aboutCommand);
mainMenu.addCommand(rtlCommand);
mainMenu.addCommand(dragModeCommand);
mainMenu.addCommand(runCommand);
mainMenu.addCommandListener(this);
mainMenu.show();
}
You need to put the images in the src folder so they get packaged in the jar (use 7zip on the jar to see what went in). You didn't provide the image URL e.g icon in src root should work like this:
"/icon.png"
精彩评论