LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 757 users online 224093 members 1002 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
xxxthunder
Music: Drum n Bass, Dubstep, Breakbeat, Techno...
Mood: Down
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
5 online / 35 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Adding Reply

Adding Reply
Archived Topic: It will not be bumped to the top of the forum.
Topic Java tip
Membername   Not a member? Sign Up Free (takes 20 seconds)
Password   Forgotten your password?
Post

Font:   Size:   Color:

FAQ Keyword Search:
Post Options
Favorites Manager
Notify me of new replies to this topic by email
Notify me of new replies to this topic by private message
Original Post
Suke Posted at 10:39 pm on Oct. 25, 2004
Alright I'm not sure how many people will find this useful but I am sharing a tip on how to properly repaint graphics to a panel when stuff happens to your gui.  For example, when it get's resized, minimized, maxmized, moved over, etc etc.. (if you don't do this, your graphics will simply disappear or flash when you move it)

All you need to do is extend the JPanel class and override the paintcomponent method in it to also call the function to redraw your graphics like so.

Code:

//class ensures proper repaint when stuff happens to panel
public class TreePanel extends JPanel
{
    public TreePanel()
    {
         setBackground(Color.white);
    }
    //override paintComponent method in JPanel
    public void paintComponent(Graphics g)
    {
         super.paintComponent(g); // call the super's paint method as normal
         Graphics2D g2 = (Graphics2D)g; // create a new graphics object
         pq.draw(g2, getWidth()); //repaint tree
    }
}//end TreePanel class

You can find a copy of this program at My prog

Open PQGui and look for the above code, then run it and see how it behaves.

Let me know if this helps you, or if everyone already knows it or a better way..

(Edited by Suke at 12:49 am on Oct. 26, 2004)

Replies
Suke Posted at 11:24 pm on Nov. 16, 2004
You should go back and comment out that class I overrided and watch how it doesn't work the at all.
sakurag Posted at 9:15 am on Oct. 26, 2004
That's a very neat program.
I've seen that kind of thing done before with trees.  Although I'm not really into writing java apps, that does give me some insight on how to do things.

We have the same idea in Win32.  Though not quite double buffering(unless it happens under the covers), does this really reduce the flickering?  I guess the Graphics object is pretty powerful.

Along these lines, I'd like to add my little tip about flicker reduction, double buffering, etc.

Double buffering is a good idea in a lot of applications.  It's almost a staple when using any sort of graphics.  But be very careful about using it.  Do not double buffer everything, unless you really need to.  Take some time to calculate which area needs to be redrawn, and redraw only it.  This can save a lot of computing power, and allow for smoother repaints, which may or may not be to your liking.  

All 2 previous replies displayed.