Results 1 to 6 of 6
- 07-25-2010, 10:00 PM #1
paintComponent vs paintComponents
hey ive imported the java.awt.*; and im trying to use the paintComponent method such as below
however my IDE (Netbeans 6.8) doesn't seem to reconise super.paintComponent(g); and instead only allows super.paintComponents(g);PHP Code:public void paintComponent(Graphics g){ super.paintComponent(g); }
could someone explain to me whats going on please?
normally i wouldnt really mind, except however paintComponents doesnt seem to work when im drawing objects, i get nothing on the screen.Teaching myself java so that i can eventually join the industry! Started in June 2010
- 07-25-2010, 10:10 PM #2
Add a @Override before the overridden method to verify the super class has that method.
paintComponent() is a Swing method. Use paint() in AWT.
-
My guess (and without more code, this is just a guess) is that you're trying to add this method to a root container such as a JApplet or a JFrame. If so, don't do this but rather do your painting in a JPanel that has a paintComponent override (using the @Override annotation as Norm recommends above).
- 07-25-2010, 10:41 PM #4
ok it worked when i extended JPanel rather than JApplet, and then i went back to extending JApplet and used the @Overide and your right, JApplet doesnt have the method PaintComponent to overide.
so instead of using paintComponent i used paint which is a method in JApplet which can be overwritten. Thanks for the help guys
Just a quick question though, im i losing any functionality using paint rather than paintComponent? (cause if i am i was thinking i could somehow put the JPanel inside the JApplet and then somehow invoke the paintComponent method, if at all possible)Teaching myself java so that i can eventually join the industry! Started in June 2010
- 07-25-2010, 11:36 PM #5
hey nevermind, i did some research and maanged this put a panel inside a Applet and thus using the original paintComponent. i havent looked into whether or not theres a difference between paintComponent and paint because cba lol, but anyways thanks for help and the @Override thingy.
Teaching myself java so that i can eventually join the industry! Started in June 2010
-
You're doing the right thing as you don't want to override a JApplet's paint method and paint directly to the applet. You want to paint into a JPanel (as I suggested above) and add that JPanel to the JApplet's contentPane.
Similar Threads
-
Trouble with paintComponent()
By ShirlyPunk in forum AWT / SwingReplies: 17Last Post: 03-13-2010, 04:27 PM -
paintComponent is not working
By spazattack in forum New To JavaReplies: 1Last Post: 12-18-2009, 03:48 AM -
Working around paintcomponent
By sahhhm in forum New To JavaReplies: 2Last Post: 05-16-2008, 02:43 AM -
Problem going outside paintComponent
By Thez in forum Java 2DReplies: 9Last Post: 12-08-2007, 04:59 PM -
paint() and paintComponent()
By goldhouse in forum Java 2DReplies: 1Last Post: 07-17-2007, 03:43 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks