Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2006

Tip: Looking for answers? Try searching our database.

Help: Overriding the paintComponent when using the Netbeans GUI Builder

Thread view: 
john - 31 Aug 2006 14:23 GMT
Hi,

I wrote a Japplet using the Netbeans's GUI builder.

On a JPanel (also created using this tool),  I would like to run some
image manipulation and therefore I'm looking for a way to override the
paintComponent. I've tried the following but it seems that it was never
executed (tired also to add some printout commands).
Any idea how can get control on the paintComponent when was build using
the GUI builder?

Thanks

John

public void paintComponent(Graphics g) {
g.drawOval(50,50,250,300);
g.drawString("Hello",50,50);

}
Andrew Thompson - 31 Aug 2006 14:55 GMT
...
> I wrote a Japplet using the Netbeans's GUI builder.

...hmm.  Applets in themselves are tricky enough, but
you want to throw a complex IDE into the mix.

Is that just to make things interesting?

> On a JPanel (also created using this tool),  I would like to run some
> image manipulation and therefore I'm looking for a way to override the
> paintComponent. I've tried the following but it seems that it was never
> executed (tired also to add some printout commands).
> Any idea how can get control on the paintComponent when was build using
> the GUI builder?

1) Why are you using the GUI builder?
(It is best to learn how Java layouts work,
by coding them)

2) Why are you using the GUI builder when also
overiding paintComponent()?

The two seem almost diametrically opposed.

> public void paintComponent(Graphics g) {
> g.drawOval(50,50,250,300);
> g.drawString("Hello",50,50);
>
> }

I'm no expert on NB and whether this should be possible,
but I suspect 'yes' in that the GUI builder would probably
allow use of custom components*, it would be very limited
otherwise.

A very limited amount of Googling also suggests that
custom components* in the 'Palette Manager' (where
do they get these names?) can be used in 'forms'.

* A custom component is one where you might overide
paint()/paintComponent(), as you attempted.

I'd be interested in hearing from the NB gurus whether
it can deal with custom components, if so, perhaps an
SSCCE** of failing code might identify the problem.

** <http://www.physci.org/codes/sscce/>

Andrew T.
john - 31 Aug 2006 16:39 GMT
> ...
> > I wrote a Japplet using the Netbeans's GUI builder.
[quoted text clipped - 45 lines]
>
> Andrew T.

You are probably right. It seems that mixing the GUI builder with
overriding paintComponent isn't a straight forward task (I just
thought it would be) so I'll probably write the swing manually.
Concerning the Reading/Writing local files from web Applets, I found a
way using CGI scripts to do it without signed classes or security
warnings. My goal is to have a stand alone web application at the end.
What do you think would be a user friendlier tool, Netbeans or Eclipse?

Regards
John
Andrew Thompson - 31 Aug 2006 17:12 GMT
Please try to put your comments *immediately after*
the relevant text, and trim other text no longer needed
(including signatures).

> > ...
> > > I wrote a Japplet using the Netbeans's GUI builder.
[quoted text clipped - 3 lines]
> >
> > Is that just to make things interesting?

> You are probably right. It seems that mixing the GUI builder with
> overriding paintComponent isn't a straight forward task (I just
> thought it would be) so I'll probably write the swing manually.

At least until you understand basically how layouts work,
I think that is a good idea.  You might find that once
you have that understanding, you can revisit the GUI
builder and get *it* to work for you as well..

> Concerning the Reading/Writing local files from web Applets, I found a
> way using CGI scripts to do it without signed classes or security
> warnings.

OK.  But my point (at that instant) was about applets in
general, rather than signed applets specifically.
Applets are harder to debug and deploy than applications.

Futher, an unsigned, web-started, application could
access those same scripts, but in a much more
predictable environment (i.e. no browser to deal with).

>  ..My goal is to have a stand alone web application at the end.

I am not sure what you mean by this mix of terms,
I would hardly consider any applet that exists in
a web-page in a browser to be 'stand alone'.

OTOH, check the ..'two applications'* you can launch here.
<http://www.physci.org/pc/>

The ones if interest are the two .jnlp files.

Click those to launch JTest (a simple program I wrote to
query the Java proerties) to see two forms of the same
application, both launched using webstart - one use the
'applet' form of the program, the other launches the
application.

Either of those unsigned applications has access back
to the server that launched them - they can 'phone home'
in the same way as an unsigned applet.

I suggest you use WebStart - and make an application.

* It is of course, neither '2', they are the same program,
nor 'applications' since one is the applet form.

> What do you think would be a user friendlier tool, Netbeans or Eclipse?

Oh that's easy.  The one I use more often* is the most
user friendly.  (And I suspect that people's answers will
almost invariably fall along those lines - even if they don't
realise it!)

* It does it matter which I use most often.   ;-)

Andrew T.
Andrew Thompson - 31 Aug 2006 17:19 GMT
..
> OTOH, check the ..'two applications'* you can launch here.
> <http://www.physci.org/pc/>
....
> Either of those unsigned applications has access back
> to the server that launched them - they can 'phone home'
> in the same way as an unsigned applet.

They do *not* do that, but my point is that (theoretically)
they *could*.  WebStart should allow it - even in an
unsigned JWS app.
...
> > What do you think would be a user friendlier tool, Netbeans or Eclipse?
>
[quoted text clipped - 4 lines]
>
> * It does it matter which I use most often.   ;-)

Oops!   'It does *not* matter which...'

Andrew T.
e_matthes@hotmail.com - 01 Sep 2006 18:26 GMT
public void paintComponent(Graphics g) {
g.drawOval(50,50,250,300);
g.drawString("Hello",50,50);

All of my recent Java work involving paintComponent has required a
casting of the Graphics object to a Graphics2D object, and a call to
super:

public void paintComponent(Graphics g) {
 super.paintComponent(g);
 Graphics2D g2d = (Graphics2D)g;
 g2d.drawOval(50,50,250,300);
 ...

Not sure if that applies to your work.

Eric


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.