473,378 Members | 1,152 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

JPanel not visible in JApplet

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all, I am experimenting with JApplet and JPanel.

My JApplet contains a JPanel called jpanel1 size 210x210.

I created a class myPanel which extends JPanel and I set its size to
210x210.

myPanel contains a Canvas called canvas1 and its size is 210x210.
But when I run the applet and draw an image to the canvas1, it is not
visible.

I call canvas1.setVisible(true), myPanel.setVisible(true) and
jpanel1.setVisible(true) and still my image is not visible.

I set canvas1.setLocation(0,0), myPanel.setLocation(0,0) and still my
image is not visible.

Is there something else that I should try to make the image visible?

Thanks,


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHAAW8QuDJiZ/QrH0RAnEhAJ41cR35MvFbu43/MkyJr5Wj+kbptACgzc0x
AK0VStBx5AtaRnJzLQ0LPW4=
=dx6/
-----END PGP SIGNATURE-----
Sep 30 '07 #1
5 10083
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

James Barrett wrote:
Hi all, I am experimenting with JApplet and JPanel.

My JApplet contains a JPanel called jpanel1 size 210x210.

I created a class myPanel which extends JPanel and I set its size to
210x210.

myPanel contains a Canvas called canvas1 and its size is 210x210.
But when I run the applet and draw an image to the canvas1, it is not
visible.

I call canvas1.setVisible(true), myPanel.setVisible(true) and
jpanel1.setVisible(true) and still my image is not visible.

I set canvas1.setLocation(0,0), myPanel.setLocation(0,0) and still my
image is not visible.

Is there something else that I should try to make the image visible?

Thanks,
I have narrowed it down but I don't fully understand why this is
happening. If I draw an image during the init() method nothing is
displayed, even if I put the setVisibale and setLocation method calls
before the drawImage method. But after the applet is inited, then images
can be drawn. but why? I want to display an image with out user
intervention, and as far as I know, that can only be done during init().
Is there another way?

Thanks,

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHABd8QuDJiZ/QrH0RAlvRAKCBqzN2qYUzR7YtgQQvSETBxWZEigCdEozA
7iNuJd1CkoRg2qBCnNNYOLY=
=mCN0
-----END PGP SIGNATURE-----
Sep 30 '07 #2
James Barrett wrote:
I have narrowed it down but I don't fully understand why this is
happening. If I draw an image during the init() method nothing is
displayed, even if I put the setVisibale and setLocation method calls
before the drawImage method. But after the applet is inited, then images
can be drawn. but why? I want to display an image with out user
intervention, and as far as I know, that can only be done during init().
Is there another way?
Typically, drawing is done by paint() and not init(). init() is the code
called when your applet is first invoked.

Perhaps you might want to look at
http://java.sun.com/docs/books/tutor...ts/applet.html ?

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
Sep 30 '07 #3
James Barrett wrote:
>Hi all, I am experimenting with JApplet and JPanel.
Be prepared for a world of trouble, dealing with applets.

Do you really need an applet, or just something that
can be launched from a link? If the latter, look instead
to a JFrame and Java Web Start.
>My JApplet contains a JPanel called jpanel1 size 210x210.

I created a class myPanel which extends JPanel and I set its size to
210x210.

myPanel contains a Canvas ...
You should not mix Swing and AWT, though I suspect
this is not the source of the propblem here.
>..called canvas1 and its size is 210x210.
Setting the preferredsize of the innermost component
should suffice in most situations, but that all becomes
redundant with applets in the sense that the entire GUI
is restrcted to the size set in the HTML.
>But when I run the applet and draw an image to the canvas1, it is not
visible.

I call canvas1.setVisible(true), myPanel.setVisible(true) and
jpanel1.setVisible(true) and still my image is not visible.
All these calls to setVisible() are redundant.
>I set canvas1.setLocation(0,0), myPanel.setLocation(0,0) and still my
image is not visible.
These calls are redundant so long as the applet
uses layouts, if it does not use layouts, it should.
If you simply aComponent.add(anotherComponent),
there will be a layout present.
>Is there something else that I should try to make the image visible?
MediaTracker.

There was a recent thread re. fading an image in an applet..
<http://www.javakb.com/Uwe/Forum.aspx/java-setup/10820/Fading-effect>
Look for Knute Johnson's code example, that shows
how to do it in a frame.

I turned the OP's version of Knute's code into an applet
that you can see here. The code is linked.
<http://www.physci.org/test/applet/slideshow/>

Failing that, try posting an SSCCE.
<http://www.physci.org/codes/sscce.html>

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.asp...neral/200710/1

Oct 1 '07 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joshua Cranmer wrote:
>
Typically, drawing is done by paint() and not init(). init() is the code
called when your applet is first invoked.

Perhaps you might want to look at
http://java.sun.com/docs/books/tutor...ts/applet.html ?
I overrode the paint method in my JPanel class, and that seemed to only
be called one time. It wasn't getting called if I minimized and then
maximized the applet. So, I then overrode the paintComponent method.
That seemed to be called only when I resize the applet. For example,if I
minimized then maximized the applet, the panel went blank until I
resized, the the Panel was painted.

I'll keep researching, but it seems like there should be way to force a
paint of the entire Panel. I could call paint directly in a timer but I
think that would defeat the purpose.

Thanks,

Jim

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHAGiDQuDJiZ/QrH0RAshHAKCfM/ZdtfVJZokrukJkbs4ePj0CrQCgradA
S6f/mMqbJEpzWNSi7ZFfvCo=
=Mf1R
-----END PGP SIGNATURE-----
Oct 1 '07 #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joshua Cranmer wrote:
James Barrett wrote:
>I have narrowed it down but I don't fully understand why this is
happening. If I draw an image during the init() method nothing is
displayed, even if I put the setVisibale and setLocation method calls
before the drawImage method. But after the applet is inited, then images
can be drawn. but why? I want to display an image with out user
intervention, and as far as I know, that can only be done during init().
Is there another way?

Typically, drawing is done by paint() and not init(). init() is the code
called when your applet is first invoked.

Perhaps you might want to look at
http://java.sun.com/docs/books/tutor...ts/applet.html ?
I think I figured it out. I was going about it wrong. Instead of
extending JPanel and adding a Canvas, I now extend canvas and override
paint(). That works. But I noticed that when the applet first loads
paint() doesn't get called or it gets called before the applet is
completely initted. So, I set a timer to call repaint() on my extended
Canvas object. This might still not be what I want but I am much farther
along than I was before.

Thanks!

Jim

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHANmyQuDJiZ/QrH0RAhCYAKDCStEHPf79o37jGLTrmXow4GdV3wCdFJia
Dr4Io3QavZ5LBsG2QZuPwxQ=
=/EaQ
-----END PGP SIGNATURE-----
Oct 1 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Eynon | last post by:
I know that the basic methods that can be overwritten for class JApplet are init, and paint. However, the API does not specifically state this, and JApplet does not describe this right away.. How...
6
by: Hal Vaughan | last post by:
I have a JPanel in a window and I am putting different components in it as the user goes through a setup wizard. In theory, I have an array of components (other JPanels), and I want to step...
0
by: Kookymon1 | last post by:
This is an attempt to respond to an older question (several months). Date: 2002-03-07 13:10:23 PST Subject: On the Common DOM API and Applets. The original message was: >LiveConnect and the...
3
by: Moth | last post by:
I have a PlotPanel class that extends JPanel which I have used previously to display charts in swing guis. I now want to display a graph in a jsp page so I was going to generate the graph and then...
2
by: Aurel | last post by:
Hi, I developped an applet (JApplet class) and now I'd like to integrate it in another application which is a JFrame one... Does anyone can help ? Thanks in advance... AureL
1
by: - | last post by:
I have googled and learned that there are limitations with JApplet writing to files on remote host. However, I am unsure as to whether it is possible to do so on the same computer. Please advice....
1
by: dishal | last post by:
Hi, Im having a problem with typing on the JPanel. The thing is, that it works perfectly fine when this line " content.add(jp, BorderLayout.NORTH); " is taken out (its the buttons panel) but when its...
8
by: eddiewould | last post by:
Hi, I want to write a custom widget which will act similarly to a JPanel (i.e it can contain other Components), but semantically it's not a kind of JPanel so it shouldn't extend from it. Here is...
1
by: Akino877 | last post by:
Hello, I have a question regarding Java and Swing programming I wonder if I could ask the forum for some help. I have a JPanel that has a couple of radio buttons and an "OK/Next" button on it. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.