Thread View: borland.public.jbuilder.java.swing
2 messages
2 total messages
Started by Ted Byers
Fri, 19 Mar 2004 21:01
Problem getting an image to dispaly in JLabel
Author: Ted Byers
Date: Fri, 19 Mar 2004 21:01
Date: Fri, 19 Mar 2004 21:01
34 lines
2069 bytes
2069 bytes
Here is the initialization code for the applet.:
//Component initialization
private void jbInit() throws Exception {
component1 = Box.createGlue();
jLabel1.setDebugGraphicsOptions(0);
jLabel1.setMinimumSize(new Dimension(700, 500));
jLabel1.setIconTextGap(4);
jLabel1.setText("");
Icon icon = new ImageIcon( "sunset.jpg" );
jLabel1.setIcon(icon);
xYLayout1.setWidth(800);
xYLayout1.setHeight(600);
this.setLayout(xYLayout1);
this.add(jLabel1, new XYConstraints(17, 23, 753, 548));
}
Although I added several jpeg and gif files to the project, and they appear
in the dropdown list for the icon of jLabel1, selecting one of them does
virtually nothing. So I added two lines of code:
Icon icon = new ImageIcon( "sunset.jpg" );
jLabel1.setIcon(icon);
Still no joy. It seems that no matter what I try, I can't get these images
to display within the applet. (NB: When the project is done, the image will
need to go into the same jar as the applet.)
What do I need to do to get this working (both from within JBuilder
9(personal) and from within a jar)?
Thanks,
Ted
Re: Problem getting an image to dispaly in JLabel
Author: Greg Hamer
Date: Mon, 22 Mar 2004 18:46
Date: Mon, 22 Mar 2004 18:46
51 lines
2985 bytes
2985 bytes
I would select the image file from the icon property drop down list and make
sure that the project is compiled. The way you are specifying it below, you
are looking for a file relative to the working directory. Reading files is
a no no in an applet, but that is not why the designer is not showing the
image. It just cannot find it when you speicify it that way. (JBuilder's
working directory is not your projects working directory). If you put the
image file in the same directory as the java file that will be using it, and
add the file to the project, the designer will be able to reference it with
an URL releative the the class that is using it, and be able to find it.
"Ted Byers" <r.ted.byers@sympatico.ca> wrote in message
news:405b5ea9$1@newsgroups.borland.com...
> Here is the initialization code for the applet.:
>
> //Component initialization
> private void jbInit() throws Exception {
> component1 = Box.createGlue();
> jLabel1.setDebugGraphicsOptions(0);
> jLabel1.setMinimumSize(new Dimension(700, 500));
> jLabel1.setIconTextGap(4);
> jLabel1.setText("");
> Icon icon = new ImageIcon( "sunset.jpg" );
> jLabel1.setIcon(icon);
> xYLayout1.setWidth(800);
> xYLayout1.setHeight(600);
> this.setLayout(xYLayout1);
> this.add(jLabel1, new XYConstraints(17, 23, 753, 548));
> }
>
> Although I added several jpeg and gif files to the project, and they
appear
> in the dropdown list for the icon of jLabel1, selecting one of them does
> virtually nothing. So I added two lines of code:
>
> Icon icon = new ImageIcon( "sunset.jpg" );
> jLabel1.setIcon(icon);
>
> Still no joy. It seems that no matter what I try, I can't get these
images
> to display within the applet. (NB: When the project is done, the image
will
> need to go into the same jar as the applet.)
>
> What do I need to do to get this working (both from within JBuilder
> 9(personal) and from within a jar)?
>
> Thanks,
>
> Ted
>
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads