Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.

[Java] Drawing complex shapes using Swing?

  • 04-03-2006 12:02PM
    #1
    Registered Users, Registered Users 2 Posts: 383
    ✭✭


    Hey guys,

    Need to draw some shapes (Like stickmen, rounded rectangles, diamonds, etc...) Is it possible to do this with out overriding the paint() or paintComponents()?

    If I use paint() I always get refresh problems, that the image disappears if some other windows (example: message box) appears over it. Any suggestions?

    thx.


Comments

  • Registered Users, Registered Users 2 Posts: 885 clearz
    ✭✭✭


    use
    JPanel drawPnl = new JPanel()
    {
        public void paintComponent(Graphics g)
        {
            super.paintComponent(g);
            /* Draw Code here */
        }
    };
    

    then add the Panel to your frame. You can of course just create a subclass of JPanel and override the paintComponent method either.


  • Registered Users, Registered Users 2 Posts: 383 cherrio
    ✭✭


    Works perfect :) thx.


Welcome!

It looks like you're new here. Sign in or register to get started.
Advertisement