0

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 JAR 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();
    }
4

1 回答 1

0

您需要将图像放在 src 文件夹中,以便将它们打包在 jar 中(使用 jar 上的 7zip 来查看其中的内容)。您没有提供图像 URL,例如 src 根目录中的图标应该像这样工作:

"/icon.png"
于 2011-05-19T09:57:21.077 回答