Advertisement
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.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

[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.


Advertisement