wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes Issue with String array and imageicon path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Issue with String array and imageicon path" Watch "Issue with String array and imageicon path" New topic
Author

Issue with String array and imageicon path

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Okay so I basically have set up an array of String names and I call a for loop on the string length to do things. One of the things is to set the icon path When I use it normally i.e.,

When I debug it says the value is equal to the original, so I'm not sure what's going on... Thoughts?

I'm also having an issue trying to get the first array element of an Array of JLabels j[0] to = an already premade JLabel named Z. I have



This doesn't work but if I replace j[i] or j[0] with JLabel j2 = Z; it works..... Why? Am I doing something wrong?




EDIT:

Okay so I figured out my first issue... I made a new string and set it to my String s, and then set s as the Resource. Pretty stupid in my opinion.. But it seems Java is like that a lot...
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jay Orsaw wrote:
When I debug it says the value is equal to the original, so I'm not sure what's going on... Thoughts?


No idea what you're saying here.

This doesn't work but if I replace j[i] or j[0] with JLabel j2 = Z; it works.....


Here either.

I made a new string and set it to my String s, and then set s as the Resource. Pretty stupid in my opinion.. But it seems Java is like that a lot...


Believe it or not the people with PhDs in Computer Science who designed the Java language actually had defensible reasons for a lot of the things they did.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Why do you declare and initialize the array inside the loop? Do you really want a new array to be created every time around the loop, one that goes out of existance when the loop terminates?


luck, db
There are no new questions, but there may be new answers.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Darryl Burke wrote:Why do you declare and initialize the array inside the loop? Do you really want a new array to be created every time around the loop, one that goes out of existance when the loop terminates?


Yeah I was pretty tired writing this. I have a question though. In other code I've noticed if I didn't do something = new Class(); I would get null pointer exceptions. I was always confused because I thought once you initiaized you were good to go and just had to set them equal to something (i.e., int[] i = new int[2]; I would just have to set both elements to something and then use them). It also has to do with what you said above....


I was able to get the code working though....



But am i still doing something I shouldn't? If I don't set the bounds I have issues, which is weird because I feel the last and second to last lines are exactly the same. If I try to just add the JLabel only it gives me an



error...

These labels are added to the Panel which is set inside of a JScrollPane. I noticed when I get the information it displays the first picture, and that's it. If I resize the applet everything is displayed within the ScrollPane(meaning I get scroll bars and I can scroll up and down). Do I have to do something with the JScrollPane, or it's Viewport? Something is being updated, and I'm not exactly sure what.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

1. AbsoluteLayout isn't a part of the standard JDK, so I can't help you there. Is there really no Swing or AWT layout that meets your requirements? They're better documented and you will always get help on a forum if you have a specific problem using one of them.

2. Applets are meant to be displayed in a browser, at a size determined by the HTML written in the APPLET or OBJECT tag. Not sure what you mean by
If I resize the applet
. But the general rule is to add all child components before the top level window is shown. In the case of an Applet, that means before the init() method returns.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Darryl Burke wrote:1. AbsoluteLayout isn't a part of the standard JDK, so I can't help you there. Is there really no Swing or AWT layout that meets your requirements? They're better documented and you will always get help on a forum if you have a specific problem using one of them.

2. Applets are meant to be displayed in a browser, at a size determined by the HTML written in the APPLET or OBJECT tag. Not sure what you mean by
If I resize the applet
. But the general rule is to add all child components before the top level window is shown. In the case of an Applet, that means before the init() method returns.



1. Sorry I forgot about that it's netbeans only. For some reason in the generated code it wants an Object parameter when adding the components, which is why I'm assuming the error is thrown. Must have to do with that absolute layer being used. That is used when using the design form in Netbeans. It's soo much easier than coding everything by hand. Of course I try to learn the code behind it all so I'm not stuck and then SOL when an error occurs or I need something beyond the basics.

2. Yeah sorry I was just running it via the IDE, when I would resize the window I should say. Interesting about the child components. I did this once before extended an applets size and creating new seperators with no issue. Would you suggest another way of doing this then? Maybe keeping the labels invisible and displaying certain ones when needed? I'm assuming when invisible it wont add unneeded space in the scrollpane?


Also like I was asking before is correct to do or is each already initialized when doing ?


EDIT: LOL wow that was ridiculously more simple.... wow.......
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Okay so now I tried building this and setting it up for use on a webpage. When I click the JNLP or the Launch for web and it runs, it gives me an error trying to read in the pictures. The main pictures are all set, but when I try to calculate and change the pictures it gives me this




479 has to do with the location of the image. Originally I changed up my class name and folder(because it wasn't running under main) then I realized there is no main and that there was an option for webstart, which I did. There was an error refactoring which I thought was the issue here, however after fixing my refactoring issues this still persists..... All of my images were imported and are in my class's package. I don't know why the other pictures aren't there if the 3 main ones are there.... Anyone have any idea why I might be having this issue....

creates the main logo and shows it.

479 is it doesn't make any sense why one logo would load, and another wouldn't. It also doesn't make sense that this works when I run it via Netbeans IDE, but doesn't run via the web nor the JNLP launcher....


Is it possible that this could be the case??

Benefits of Separating Core Functionality From the Final Deployment Mechanism

Another way to create an applet is to just remove the layer of abstraction (separate top JPanel) and lay out all the controls in the applet's init method itself. The downside to creating the GUI directly in the applet is that it will now be more difficult to deploy your functionality as a Java Web Start application, if you choose to do so later.

In the Dynamic Tree Demo example, the core functionality resides in the DynamicTreePanel class. It is now trivial to drop the DynamicTreePanel class into a JFrame and deploy as a Java Web Start application.

Hence, to preserve portability and keep deployment options open, follow component-based design as described on this page.

http://docs.oracle.com/javase/tutorial/deployment/applet/developingApplet.html

I have everything coded in 1 JApplet Form in Netbeans, but I actually stumbled upon this today when learning more about applets.... Should I have it in a seperate class then call that class?

EDIT: In the include it shows all the pictures as well.. weird....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue with String array and imageicon path