By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,255 Members | 2,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,255 IT Pros & Developers. It's quick & easy.

dynamically setting screen width in an applet

P: n/a
Hello,

Newbie question: Does anyone know how to dynamically set the screen
width in an applet? I have an applet that creates a horizontal bar
menu on a webpage, and I would like the width to be 100%.
Unfortunately, this doesn't work with Explorer. so, in my html page,
I wrote a function like this:

<SCRIPT LANGUAGE="JavaScript">
int function getScreenWidth()
{
var width = window.screen.width;
return width;
}
</SCRIPT>

and then called the function when running the applet:
<applet Code=Menu.class Width="getScreenWidth()" Height=30>

but this doesn't seem to work. Can anyone tell me how to fix this?
The script is between the <head></head> tags.

Thanks in advance!
Laura
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 30 Jul 2003 10:16:27 -0700, sa******@aecl.ca (Laura) two-finger typed:
Hello,

Newbie question: Does anyone know how to dynamically set the screen
width in an applet? I have an applet that creates a horizontal bar
menu on a webpage, and I would like the width to be 100%.
Unfortunately, this doesn't work with Explorer.
What doesn't work ?

Have you tried <APPLET CODE=... WIDTH="100%" HEIGHT=... > ?
That should work fine, just not in appletviewer (no surrounding page to be
a percentage of).
so, in my html page,
I wrote a function like this:

<SCRIPT LANGUAGE="JavaScript">
int function getScreenWidth()
{
var width = window.screen.width;
return width;
}
</SCRIPT>

and then called the function when running the applet:
<applet Code=Menu.class Width="getScreenWidth()" Height=30>
There is no indication to the browser that you are using javascript inside
a javascript supporting parameter, because the WIDTH parameter works like
any width parameter in HTML, and does not interpret Javascript functions
like onLoad or onMouseOver would.

And I hope you mean not 'screen' width, but the width of the HTML page,
because you can't load an Applet geometrically outside the HTML page.
Not everybody runs their browser fullscreen.

The Applet could create a new window outside the page, though, but I don't
think that is what you are looking for.

but this doesn't seem to work. Can anyone tell me how to fix this?
The script is between the <head></head> tags.

Thanks in advance!
Laura


Cheers.
Jul 17 '05 #2

P: n/a
Yeah, the % doesn't seem to work for me. As soon as I change this to
pixels, everything is ok, but when I use percents, it's blank on the
screen... I wonder why. I was thinking of maybe passing width as a
param? Do you think this would work?

thanks again!
Laura
Neomorph <ne******@nospam.demon.co.uk> wrote in message news:<1k********************************@4ax.com>. ..
On 30 Jul 2003 10:16:27 -0700, sa******@aecl.ca (Laura) two-finger typed:
Hello,

Newbie question: Does anyone know how to dynamically set the screen
width in an applet? I have an applet that creates a horizontal bar
menu on a webpage, and I would like the width to be 100%.
Unfortunately, this doesn't work with Explorer.


What doesn't work ?

Have you tried <APPLET CODE=... WIDTH="100%" HEIGHT=... > ?
That should work fine, just not in appletviewer (no surrounding page to
be
a percentage of).
so, in my html page,
I wrote a function like this:

<SCRIPT LANGUAGE="JavaScript">
int function getScreenWidth()
{
var width = window.screen.width;
return width;
}
</SCRIPT>

and then called the function when running the applet:
<applet Code=Menu.class Width="getScreenWidth()" Height=30>


There is no indication to the browser that you are using javascript
inside
a javascript supporting parameter, because the WIDTH parameter works like
any width parameter in HTML, and does not interpret Javascript functions
like onLoad or onMouseOver would.

And I hope you mean not 'screen' width, but the width of the HTML page,
because you can't load an Applet geometrically outside the HTML page.
Not everybody runs their browser fullscreen.

The Applet could create a new window outside the page, though, but I
don't
think that is what you are looking for.

but this doesn't seem to work. Can anyone tell me how to fix this?
The script is between the <head></head> tags.

Thanks in advance!
Laura


Cheers.

Jul 17 '05 #3

P: n/a
On 31 Jul 2003 11:23:32 -0700, sa******@aecl.ca (Laura) two-finger typed:
Yeah, the % doesn't seem to work for me. As soon as I change this to
pixels, everything is ok, but when I use percents, it's blank on the
screen... I wonder why. I was thinking of maybe passing width as a
param? Do you think this would work?
Are you using a table around the applet ?

If you do, make sure the table has a width=100% as well.

If you let the cell/column of the table that contains the applet minimize
on the content, then giving the applet a percentage will 'shortcircuit' the
sizing calculation and you end up with a zero width column.

thanks again!
Laura
Neomorph <ne******@nospam.demon.co.uk> wrote in message news:<1k********************************@4ax.com>. ..
On 30 Jul 2003 10:16:27 -0700, sa******@aecl.ca (Laura) two-finger typed:
>Hello,
>
>Newbie question: Does anyone know how to dynamically set the screen
>width in an applet? I have an applet that creates a horizontal bar
>menu on a webpage, and I would like the width to be 100%.
>Unfortunately, this doesn't work with Explorer.


What doesn't work ?

Have you tried <APPLET CODE=... WIDTH="100%" HEIGHT=... > ?


<cut rest>

Cheers.
Jul 17 '05 #4

P: n/a
Yup, my applet is in a table, but I tried setting the width in teh
table, and also in the applet and it didn't work. I was wondering if
there was a different way to fix this?
thanks again, Laura
Neomorph <ne******@nospam.demon.co.uk> wrote in message news:<5q********************************@4ax.com>. ..
On 31 Jul 2003 11:23:32 -0700, sa******@aecl.ca (Laura) two-finger typed:
Yeah, the % doesn't seem to work for me. As soon as I change this to
pixels, everything is ok, but when I use percents, it's blank on the
screen... I wonder why. I was thinking of maybe passing width as a
param? Do you think this would work?


Are you using a table around the applet ?

If you do, make sure the table has a width=100% as well.

If you let the cell/column of the table that contains the applet minimize
on the content, then giving the applet a percentage will 'shortcircuit'
the
sizing calculation and you end up with a zero width column.

thanks again!
Laura
Neomorph <ne******@nospam.demon.co.uk> wrote in message

news:<1k********************************@4ax.com>. ..
On 30 Jul 2003 10:16:27 -0700, sa******@aecl.ca (Laura) two-finger typed:
>Hello,
>
>Newbie question: Does anyone know how to dynamically set the screen
>width in an applet? I have an applet that creates a horizontal bar
>menu on a webpage, and I would like the width to be 100%.
>Unfortunately, this doesn't work with Explorer.

What doesn't work ?

Have you tried <APPLET CODE=... WIDTH="100%" HEIGHT=... > ?


<cut rest>

Cheers.

Jul 17 '05 #5

P: n/a
On 5 Aug 2003 08:24:21 -0700, sa******@aecl.ca (Laura) two-finger typed:
Yup, my applet is in a table, but I tried setting the width in the
table, and also in the applet and it didn't work. I was wondering if
there was a different way to fix this?
thanks again, Laura
Make sure there is no setSize() in the Applet's init().
I use Visual Café 4.0 for Java development, and the visual editor has the
nasty habit of wanting to set the size in the init() of the Applet.

The % on the width or height of the Applet tag is with respect to the
container around it (the table cell in your case), not neccessarily with
the window of the browser.

Also, when you use too many relative sizes, is can happen that there is no
way to calculate the real size, because there is no size to relate to.

Example (I left out the pointy brackets so HTML news readers don't try to
interpret this as HTML):

TABLE WIDTH=90% !-- 90% of the window width - no problem here --
TR
TD
!-- Applet wants 100% of the cell (not the table!) --
APPLET ... WIDTH=100% HEIGHT=100
/APPET
/TD

TD
Hello World
/TD
<!-- Autoadjust size -->
<TR>
</TABLE>

Since Hello World uses actual real estate, and the first column could be
zero width without conflicting with the size of the object(s) inside (100%
of zero is zero, so it fits), the second column could practically take the
entire 90% of the window width.

If you would post your actial HTML (or a link to it), we could have a look
at it and tell you were the problem lies.
Neomorph <ne******@nospam.demon.co.uk> wrote in message news:<5q********************************@4ax.com>. ..
On 31 Jul 2003 11:23:32 -0700, sa******@aecl.ca (Laura) two-finger typed:
>Yeah, the % doesn't seem to work for me. As soon as I change this to
>pixels, everything is ok, but when I use percents, it's blank on the
>screen... I wonder why. I was thinking of maybe passing width as a
>param? Do you think this would work?


Are you using a table around the applet ?

If you do, make sure the table has a width=100% as well.


Cheers.
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.